Skip site navigation (1) Skip section navigation (2)

Odd numeric->float4/8 casting behaviour

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Odd numeric->float4/8 casting behaviour
Date: 2007-01-04 15:37:59
Message-ID: 87wt42vm3s.fsf@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-hackers
I noticed this odd discrepancy:

postgres=# select -0.999::numeric(3,3)::float4 = -0.999::numeric(3,3);
 ?column? 
----------
 f
(1 row)


I believe this is happening because the numeric is being cast to float8 and
then the float4-float8 cross-data-type operator is being used. It seems like
it would be preferable to cast it to float4 and use the non-cross-data-type
operator. They're both marked as implicit casts so I'm unclear what decides
which gets used.

Also, as a side note I was surprised to find the above being parsed as
-(0.999::numeric(3,3)) rather than (-0.999)::numeric(3,3) is that expected?



regression=# create or replace view x as select   -0.999::numeric(3,3)::float4 = -0.999::numeric(3,3);
CREATE VIEW
regression=# \d x
        View "public.x"
  Column  |  Type   | Modifiers 
----------+---------+-----------
 ?column? | boolean | 
View definition:
 SELECT (- 0.999::numeric(3,3)::real) = (- 0.999::numeric(3,3))::double precision;

regression=# create or replace view x as select   (-0.999)::numeric(3,3)::float4 = (-0.999)::numeric(3,3);
CREATE VIEW
regression=# \d x
        View "public.x"
  Column  |  Type   | Modifiers 
----------+---------+-----------
 ?column? | boolean | 
View definition:
 SELECT -0.999::numeric(3,3)::real = -0.999::numeric(3,3)::double precision;


-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com

Responses

pgsql-hackers by date

Next:From: Mario WeilguniDate: 2007-01-04 15:41:36
Subject: Re: InitPostgres and flatfiles question
Previous:From: Tom LaneDate: 2007-01-04 15:36:48
Subject: Re: InitPostgres and flatfiles question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group