on 2013 Oct 09 3:16 AM
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?
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)).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
10 | |
10 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.