summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorAlvaro Herrera2015-04-03 20:33:05 +0000
committerAlvaro Herrera2015-04-03 20:33:05 +0000
commit9550e8348b7965715789089555bb5a3fda8c269c (patch)
tree97ae0663caae7308e8f7f87f5647783ac2387647 /src/backend/commands
parent4ff695b17d32a9c330952192dbc789d31a5e2f5e (diff)
Transform ALTER TABLE/SET TYPE/USING expr during parse analysis
This lets later stages have access to the transformed expression; in particular it allows DDL-deparsing code during event triggers to pass the transformed expression to ruleutils.c, so that the complete command can be deparsed. This shuffles the timing of the transform calls a bit: previously, nothing was transformed during parse analysis, and only the RELKIND_RELATION case was being handled during execution. After this patch, all expressions are transformed during parse analysis (including those for relkinds other than RELATION), and the error for other relation kinds is thrown only during execution. So we do more work than before to reject some bogus cases. That seems acceptable.
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/tablecmds.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 002319e8a02..eecc30f783f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7776,7 +7776,7 @@ ATPrepAlterColumnType(List **wqueue,
char *colName = cmd->name;
ColumnDef *def = (ColumnDef *) cmd->def;
TypeName *typeName = def->typeName;
- Node *transform = def->raw_default;
+ Node *transform = def->cooked_default;
HeapTuple tuple;
Form_pg_attribute attTup;
AttrNumber attnum;
@@ -7835,34 +7835,13 @@ ATPrepAlterColumnType(List **wqueue,
{
/*
* Set up an expression to transform the old data value to the new
- * type. If a USING option was given, transform and use that
- * expression, else just take the old value and try to coerce it. We
- * do this first so that type incompatibility can be detected before
- * we waste effort, and because we need the expression to be parsed
- * against the original table row type.
+ * type. If a USING option was given, use the expression as transformed
+ * by transformAlterTableStmt, else just take the old value and try to
+ * coerce it. We do this first so that type incompatibility can be
+ * detected before we waste effort, and because we need the expression
+ * to be parsed against the original table row type.
*/
- if (transform)
- {
- RangeTblEntry *rte;
-
- /* Expression must be able to access vars of old table */
- rte = addRangeTableEntryForRelation(pstate,
- rel,
- NULL,
- false,
- true);
- addRTEtoQuery(pstate, rte, false, true, true);
-
- transform = transformExpr(pstate, transform,
- EXPR_KIND_ALTER_COL_TRANSFORM);
-
- /* It can't return a set */
- if (expression_returns_set(transform))
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("transform expression must not return a set")));
- }
- else
+ if (!transform)
{
transform = (Node *) makeVar(1, attnum,
attTup->atttypid, attTup->atttypmod,