cancel
Showing results for 
Search instead for 
Did you mean: 

SELECT ABS(-1.5) returning a string result via C API?

Former Member
3,244

I'm using SQLAnywhere 12.0.1 build 3798 via the C api.

When I perform the query: SELECT ABS(-1.5) and fetch results:

a_sqlany_column_info colInfo;
a_sqlany_data_value value;
a_sqlany_stmt* stmt = api.sqlany_prepare(_connection, "SELECT ABS(-1.5)");
api.sqlany_fetch_next(stmt);
api.sqlany_get_column_info(stmt, 0, &colInfo);
int rc = api.sqlany_get_column(stmt, 0, &value);

I find that colInfo.type and value.type are both set as A_STRING, and the first three bytes of value.buffer are set to the c string: "1.5".

This seems to be specific to ABS() -- SELECT statements calling CEILING(), FLOOR(), EXP(), LOG(), and similar built-in functions all seem to return native double-precision floating point values, while ABS is returning a human-readable string containing a number. Is this intentional?

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

That is expected behaviour:

The literal value 1.5 is a NUMERIC(2,1), as can be tested by using the EXPRTYPE buitin function. In contrast to other mathematical functions, ABS() seems to return the input type if possible - confine the docs. For NUMERIC input values, the return type is NUMERIC, too. According to that,

select exprtype('SELECT -1.5', 1), exprtype('SELECT ABS(-1.5)', 1)

returns "numeric(2,1), numeric(2,1).

And for most APIs, NUMERIC will be returned as a string value.

If you would like a floating-point type (say, a double), you can easily cast the input value or the expression itself to the desired type, such as SELECT ABS(CAST(-1.5 AS DOUBLE)).

Answers (0)