aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/makefuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-09-06 17:31:58 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-09-06 17:31:58 +0000
commitf8942f4a15fa5baa51c52491147a1bb910532332 (patch)
treed8d7b6f9cb19ebbad98e8893abff208a42e492fb /src/backend/nodes/makefuncs.c
parent190df8a4cfc2a9df911f001b1601c4cc937d5a07 (diff)
downloadpostgresql-f8942f4a15fa5baa51c52491147a1bb910532332.tar.gz
postgresql-f8942f4a15fa5baa51c52491147a1bb910532332.zip
Make eval_const_expressions() preserve typmod when simplifying something like
null::char(3) to a simple Const node. (It already worked for non-null values, but not when we skipped evaluation of a strict coercion function.) This prevents loss of typmod knowledge in situations such as exhibited in bug #3598. Unfortunately there seems no good way to fix that bug in 8.1 and 8.2, because they simply don't carry a typmod for a plain Const node. In passing I made all the other callers of makeNullConst supply "real" typmod values too, though I think it probably doesn't matter anywhere else.
Diffstat (limited to 'src/backend/nodes/makefuncs.c')
-rw-r--r--src/backend/nodes/makefuncs.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index d9d61d4f0bb..429a16cdfea 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.56 2007/06/23 22:12:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.57 2007/09/06 17:31:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -174,19 +174,20 @@ makeConst(Oid consttype,
/*
* makeNullConst -
- * creates a Const node representing a NULL of the specified type
+ * creates a Const node representing a NULL of the specified type/typmod
*
- * Note: for all current uses, OK to set typmod of the Const to -1.
+ * This is a convenience routine that just saves a lookup of the type's
+ * storage properties.
*/
Const *
-makeNullConst(Oid consttype)
+makeNullConst(Oid consttype, int32 consttypmod)
{
int16 typLen;
bool typByVal;
get_typlenbyval(consttype, &typLen, &typByVal);
return makeConst(consttype,
- -1,
+ consttypmod,
(int) typLen,
(Datum) 0,
true,