dbTalk Databases Forums  

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

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


Discuss Re: [BUGS] 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   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Unexpected behaviour of numeric datatype when mixed with,float4, domains and plpgsql variables - 04-10-2005 , 04:21 PM






Ezequiel Tolnay <mail (AT) etolnay (DOT) com.ar> writes:
Quote:
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;
plpgsql doesn't currently enforce domain constraints, so the assignment
to n isn't doing the rounding that you expect. Until someone gets
around to fixing that, an explicit coercion is probably what you need:

n := cast($1 * 0.2::float4 AS currency);

Keep in mind also that declaring a function result value as a domain
is pretty dangerous, because none of the PLs enforce domain constraints
on their results.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


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.