The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

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?

asked 09 Oct '13, 02:16

Trevor%20Powell's gravatar image

Trevor Powell
81228
accept rate: 0%

edited 09 Oct '13, 05:55

Volker%20Barth's gravatar image

Volker Barth
29.3k287438644


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
29.3k287438644
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×25
×6

question asked: 09 Oct '13, 02:16

question was seen: 1,412 times

last updated: 09 Oct '13, 05:55