Bug #15469 UDF Documentation: unclear how to handle Item_result::DECIMAL_RESULT arguments
Submitted: 4 Dec 2005 12:38 Modified: 6 Sep 2006 17:58
Reporter: Roland Bouman Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0.16 OS:NA
Assigned to: Paul Dubois CPU Architecture:Any
Triage: D4 (Minor)

[4 Dec 2005 12:38] Roland Bouman
Description:
The documentation on UDF argument handling (http://dev.mysql.com/doc/refman/5.1/en/udf-arguments.html) quite clearly documents how to handle arguments for the categories STRING_RESULT, REAL_RESULT and INT_RESULT. 
However, mysql_com.h defines two more types:

enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
                  DECIMAL_RESULT};

ROW_RESULT and DECIMAL_RESULT.

I don't know about ROW_RESULT, but I bump into DECIMAL_RESULT quite a few times. Passing a value like

1.0

gives me a UDF_ARGS *args->arg_type[x] == DECIMAL_RESULT.

I'd like to handle this type of argument, but I don't know how I should cast the corresponding UDF_ARGS * args->args[x] entry so I can work it inside C. 

In addition, it would be nice to also include documentation on how to return a decimal

How to repeat:
NA

Suggested fix:
Document this additional argument type
[4 Dec 2005 13:14] Valeriy Kravchuk
Thank you for a documentation request. Yes, handling of DECIMAL_RESULT (and  ROW_RESULT) should be described at http://dev.mysql.com/doc/refman/5.0/en/udf-arguments.html.
[5 Dec 2005 20:52] Paul Dubois
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).

Additional info:

DECIMAL functions can be declared but their values are
returned as strings, so you write them like STRING functions.

ROW is unimplemented and cannot be used.  The manual
will not document a non-existent syntax.
[3 Feb 2006 15:09] Roland Bouman
The documentation still does not reflect the addition of the DECIMAL_RESULT (http://dev.mysql.com/doc/refman/5.0/en/udf-arguments.html) shouldnt it be there already? it's been nearly 2 months...
[3 Feb 2006 15:10] Roland Bouman
same goes for 5.1:

http://dev.mysql.com/doc/refman/5.1/en/udf-arguments.html
[19 Aug 2006 3:01] Morgan Tocker
Reopening original bug;
When writing a udf with float arguments - ie sample_udf(4.5, 5.6) the arguments are reported to be of type DECIMAL_RESULT not REAL_RESULT as the docs suggest.
[25 Aug 2006 13:55] Valeriy Kravchuk
DECIMAL_RESULT still have to be documented.
[6 Sep 2006 17:58] Paul Dubois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

DECIMAL_RESULT arguments are passed as strings, but you can use the
init function to coerce them to numbers.  I've added instructions
at http://dev.mysql.com/doc/refman/5.0/en/udf-arguments.html, and
also the following incompatibility note in the 5.0.3 changelog and
the 5.0 upgrade section.

Warning: Incompatible change: For user-defined functions, exact-value
decimal arguments such as 1.3 or DECIMAL column values were passed as
REAL_RESULT values prior to MySQL 5.0.3. As of 5.0.3, they are passed
as strings with a type of DECIMAL_RESULT. If you upgrade to 5.0.3 and
find that your UDF now receives string values, use the initialization
function to coerce the arguments to numbers as described in
http://dev.mysql.com/doc/refman/5.0/en/udf-arguments.html.

Also added notes were appropriate that ROW_RESULT return values and
arguments are not implemented.