From: Tom Lane Date: Thu, 2 Apr 2009 01:16:25 +0000 (+0000) Subject: plpgsql's exec_simple_cast_value() mistakenly supposed that it could bypass X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=8b8b0138521c134d1ac53ac1fd889e1eb3d893b6;p=users%2Fbernd%2Fpostgres.git plpgsql's exec_simple_cast_value() mistakenly supposed that it could bypass casting effort whenever the input value was NULL. However this prevents application of not-null domain constraints in the cases that use this function, as illustrated in bug #4741. Since this function isn't meant for use in performance-critical paths anyway, this certainly seems like another case of "premature optimization is the root of all evil". Back-patch as far as 8.2; older versions made no effort to enforce domain constraints here anyway. --- diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index ca4f33e103..81c71e6c80 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -4351,26 +4351,23 @@ exec_simple_cast_value(Datum value, Oid valtype, Oid reqtype, int32 reqtypmod, bool isnull) { - if (!isnull) + if (valtype != reqtype || reqtypmod != -1) { - if (valtype != reqtype || reqtypmod != -1) - { - Oid typinput; - Oid typioparam; - FmgrInfo finfo_input; + Oid typinput; + Oid typioparam; + FmgrInfo finfo_input; - getTypeInputInfo(reqtype, &typinput, &typioparam); + getTypeInputInfo(reqtype, &typinput, &typioparam); - fmgr_info(typinput, &finfo_input); + fmgr_info(typinput, &finfo_input); - value = exec_cast_value(value, - valtype, - reqtype, - &finfo_input, - typioparam, - reqtypmod, - isnull); - } + value = exec_cast_value(value, + valtype, + reqtype, + &finfo_input, + typioparam, + reqtypmod, + isnull); } return value;