Re: numeric cast oddity

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, Sim Zacks <sim(at)compulab(dot)co(dot)il>, pgsql-general(at)postgresql(dot)org, Sandy Oz <alexandra(at)compulab(dot)co(dot)il>
Subject: Re: numeric cast oddity
Date: 2009-12-03 16:23:01
Message-ID: 10122.1259857381@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dave Huber 2009-12-03 17:17:32 code example for PQgetCopyData
Previous Message Frank Sweetser 2009-12-03 16:16:57 Re: [Bacula-users] Catastrophic changes to PostgreSQL 8.4