Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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_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?

asked 09 Oct '13, 02:16

Trevor%20Powell's gravatar image

Trevor Powell
accept rate: 0%

edited 09 Oct '13, 05:55

Volker%20Barth's gravatar image

Volker Barth

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)).

permanent link

answered 09 Oct '13, 05:54

Volker%20Barth's gravatar image

Volker Barth
accept rate: 34%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 09 Oct '13, 02:16

question was seen: 3,066 times

last updated: 09 Oct '13, 05:55