Re: numeric cast oddity - Mailing list pgsql-general

From Tom Lane
Subject Re: numeric cast oddity
Date
Msg-id 10122.1259857381@sss.pgh.pa.us
Whole thread Raw
In response to Re: numeric cast oddity  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: numeric cast oddity  (Sim Zacks <sim@compulab.co.il>)
List pgsql-general
I wrote:
> which are indeed different (might be worth looking into why)

Oh: the reason they're different is that these expressions are not
actually the same thing.  Minus binds less tightly than typecast.
You get consistent results if you input equivalent expressions:

regression=# select cast(-1 as numeric(20,4));
 numeric
---------
 -1.0000
(1 row)

regression=# select (-1)::numeric(20,4);
 numeric
---------
 -1.0000
(1 row)

regression=# select - cast(1 as numeric(20,4));
 ?column?
----------
  -1.0000
(1 row)

regression=# select - 1::numeric(20,4);
 ?column?
----------
  -1.0000
(1 row)

What we're actually seeing here is that the code to guess a default
column name doesn't descend through a unary minus operator, it just
punts upon finding an Op node.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: numeric cast oddity
Next
From: Dave Huber
Date:
Subject: code example for PQgetCopyData