Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 24a814f

Browse files
committed
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.
1 parent bfd17f9 commit 24a814f

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/pl/plpgsql/src/pl_exec.c

+14-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.236 2009/03/26 22:26:08 petere Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.237 2009/04/02 01:16:11 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4754,26 +4754,23 @@ exec_simple_cast_value(Datum value, Oid valtype,
47544754
Oid reqtype, int32 reqtypmod,
47554755
bool isnull)
47564756
{
4757-
if (!isnull)
4757+
if (valtype != reqtype || reqtypmod != -1)
47584758
{
4759-
if (valtype != reqtype || reqtypmod != -1)
4760-
{
4761-
Oid typinput;
4762-
Oid typioparam;
4763-
FmgrInfo finfo_input;
4759+
Oid typinput;
4760+
Oid typioparam;
4761+
FmgrInfo finfo_input;
47644762

4765-
getTypeInputInfo(reqtype, &typinput, &typioparam);
4763+
getTypeInputInfo(reqtype, &typinput, &typioparam);
47664764

4767-
fmgr_info(typinput, &finfo_input);
4765+
fmgr_info(typinput, &finfo_input);
47684766

4769-
value = exec_cast_value(value,
4770-
valtype,
4771-
reqtype,
4772-
&finfo_input,
4773-
typioparam,
4774-
reqtypmod,
4775-
isnull);
4776-
}
4767+
value = exec_cast_value(value,
4768+
valtype,
4769+
reqtype,
4770+
&finfo_input,
4771+
typioparam,
4772+
reqtypmod,
4773+
isnull);
47774774
}
47784775

47794776
return value;

0 commit comments

Comments
 (0)