1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

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.
This commit is contained in:
Tom Lane
2007-09-06 17:31:58 +00:00
parent 190df8a4cf
commit f8942f4a15
10 changed files with 31 additions and 26 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.231 2007/08/21 01:11:14 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.232 2007/09/06 17:31:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -3179,12 +3179,15 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
if (!defval && GetDomainConstraints(typeOid) != NIL)
{
Oid basetype = getBaseType(typeOid);
Oid baseTypeId;
int32 baseTypeMod;
defval = (Expr *) makeNullConst(basetype);
baseTypeMod = typmod;
baseTypeId = getBaseTypeAndTypmod(typeOid, &baseTypeMod);
defval = (Expr *) makeNullConst(baseTypeId, baseTypeMod);
defval = (Expr *) coerce_to_target_type(NULL,
(Node *) defval,
basetype,
baseTypeId,
typeOid,
typmod,
COERCION_ASSIGNMENT,