diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-22 17:20:05 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-22 17:20:05 +0000 |
commit | 9309d5f2ba00f3d918bc2f7998440be89fbde85b (patch) | |
tree | f45b43f401ad6202b528b007b79e561032c485ba /src/backend/commands/tablecmds.c | |
parent | 4733dcc592c0b9c3b928d248f5b80eafec1fb81d (diff) |
In ALTER COLUMN TYPE, strip any implicit coercion operations appearing
at the top level of the column's old default expression before adding
an implicit coercion to the new column type. This seems to satisfy the
principle of least surprise, as per discussion of bug #1290.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 463d2506c2e..36162758583 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.136 2004/10/21 21:33:59 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.137 2004/10/22 17:20:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -4738,13 +4738,20 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, * changing the column type, because build_column_default itself will * try to coerce, and will not issue the error message we want if it * fails.) + * + * We remove any implicit coercion steps at the top level of the old + * default expression; this has been agreed to satisfy the principle + * of least surprise. (The conversion to the new column type should + * act like it started from what the user sees as the stored expression, + * and the implicit coercions aren't going to be shown.) */ if (attTup->atthasdef) { defaultexpr = build_column_default(rel, attnum); Assert(defaultexpr); + defaultexpr = strip_implicit_coercions(defaultexpr); defaultexpr = coerce_to_target_type(NULL, /* no UNKNOWN params */ - defaultexpr, exprType(defaultexpr), + defaultexpr, exprType(defaultexpr), targettype, typename->typmod, COERCION_ASSIGNMENT, COERCE_IMPLICIT_CAST); |