![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Ezequiel Tolnay <mail (AT) etolnay (DOT) com.ar> writes: 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); Please note that the critical issue is a column defined as numeric(15,4) |
![]() |
| Thread Tools | |
| Display Modes | |
| |