dbTalk Databases Forums  

[BUGS] BUG #1587: Unexpected behaviour of numeric datatype when mixed with float4, domains and plpgsql variables

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1587: Unexpected behaviour of numeric datatype when mixed with float4, domains and plpgsql variables in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ezequiel Tolnay
 
Posts: n/a

Default [BUGS] BUG #1587: Unexpected behaviour of numeric datatype when mixed with float4, domains and plpgsql variables - 04-10-2005 , 02:26 PM







The following bug has been logged online:

Bug reference: 1587
Logged by: Ezequiel Tolnay
Email address: mail (AT) etolnay (DOT) com.ar
PostgreSQL version: 8.0.1
Operating system: Windows XP Advanced Server
Description: Unexpected behaviour of numeric datatype when mixed with
float4, domains and plpgsql variables
Details:

Tables with columns specified as numeric through the use of a domain are
capable of containing values with a higher precision than allowed.

The following snippet can be used to reproduce the error (run each step
sequencially and observe results):
--step 1: direct execution on base type
SELECT 92::numeric(15,4) * 0.2::float4;

--step 2: using a function variable and a domain
CREATE DOMAIN currency AS numeric(15,4);
CREATE TABLE test (id serial, amt currency);
CREATE FUNCTION f_test(currency) RETURNS currency AS $$
DECLARE n currency;
BEGIN n := $1 * 0.2::float4;
INSERT INTO test (amt) VALUES (n); RETURN n;
END $$ LANGUAGE PLPGSQL;
SELECT f_test(92);

--step 3: wrong precision stored in the table!
SELECT id, amt, amt::currency as amt_still_bad,
amt::numeric(15,4) as amt_casted_as_base,
amt::float::currency as amt_casted_back_n_forth
FROM test;

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.