diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-11-24 23:21:06 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-11-24 23:21:45 -0500 |
commit | 9ed439a9c07b69c2617cc98596611fdbdc22472c (patch) | |
tree | 67de5b64612bdcd4006e0a00730aa87e49aa73bb /src/backend/parser/analyze.c | |
parent | e90710f34a6d5a73475e4241852b377675600325 (diff) | |
download | postgresql-9ed439a9c07b69c2617cc98596611fdbdc22472c.tar.gz postgresql-9ed439a9c07b69c2617cc98596611fdbdc22472c.zip |
Fix unsupported options in CREATE TABLE ... AS EXECUTE.
The WITH [NO] DATA option was not supported, nor the ability to specify
replacement column names; the former limitation wasn't even documented, as
per recent complaint from Naoya Anzai. Fix by moving the responsibility
for supporting these options into the executor. It actually takes less
code this way ...
catversion bump due to change in representation of IntoClause, which might
affect stored rules.
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r-- | src/backend/parser/analyze.c | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index e4a4e3a5e48..dae54783931 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -56,7 +56,6 @@ static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt, bool isTopLevel, List **targetlist); static void determineRecursiveColTypes(ParseState *pstate, Node *larg, List *nrtargetlist); -static void applyColumnNames(List *dst, List *src); static Query *transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt); static List *transformReturningList(ParseState *pstate, List *returningList); static Query *transformDeclareCursorStmt(ParseState *pstate, @@ -964,13 +963,8 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) pstate->p_windowdefs, &qry->targetList); - /* handle any SELECT INTO/CREATE TABLE AS spec */ - if (stmt->intoClause) - { - qry->intoClause = stmt->intoClause; - if (stmt->intoClause->colNames) - applyColumnNames(qry->targetList, stmt->intoClause->colNames); - } + /* SELECT INTO/CREATE TABLE AS spec is just passed through */ + qry->intoClause = stmt->intoClause; qry->rtable = pstate->p_rtable; qry->jointree = makeFromExpr(pstate->p_joinlist, qual); @@ -1191,13 +1185,8 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("SELECT FOR UPDATE/SHARE cannot be applied to VALUES"))); - /* handle any CREATE TABLE AS spec */ - if (stmt->intoClause) - { - qry->intoClause = stmt->intoClause; - if (stmt->intoClause->colNames) - applyColumnNames(qry->targetList, stmt->intoClause->colNames); - } + /* CREATE TABLE AS spec is just passed through */ + qry->intoClause = stmt->intoClause; /* * There mustn't have been any table references in the expressions, else @@ -1268,7 +1257,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) int leftmostRTI; Query *leftmostQuery; SetOperationStmt *sostmt; - List *intoColNames = NIL; List *sortClause; Node *limitOffset; Node *limitCount; @@ -1306,11 +1294,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) leftmostSelect = leftmostSelect->larg; Assert(leftmostSelect && IsA(leftmostSelect, SelectStmt) && leftmostSelect->larg == NULL); - if (leftmostSelect->intoClause) - { - qry->intoClause = leftmostSelect->intoClause; - intoColNames = leftmostSelect->intoClause->colNames; - } + qry->intoClause = leftmostSelect->intoClause; /* clear this to prevent complaints in transformSetOperationTree() */ leftmostSelect->intoClause = NULL; @@ -1460,19 +1444,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) qry->limitCount = transformLimitClause(pstate, limitCount, "LIMIT"); - /* - * Handle SELECT INTO/CREATE TABLE AS. - * - * Any column names from CREATE TABLE AS need to be attached to both the - * top level and the leftmost subquery. We do not do this earlier because - * we do *not* want sortClause processing to be affected. - */ - if (intoColNames) - { - applyColumnNames(qry->targetList, intoColNames); - applyColumnNames(leftmostQuery->targetList, intoColNames); - } - qry->rtable = pstate->p_rtable; qry->jointree = makeFromExpr(pstate->p_joinlist, NULL); @@ -1892,44 +1863,6 @@ determineRecursiveColTypes(ParseState *pstate, Node *larg, List *nrtargetlist) analyzeCTETargetList(pstate, pstate->p_parent_cte, targetList); } -/* - * Attach column names from a ColumnDef list to a TargetEntry list - * (for CREATE TABLE AS) - */ -static void -applyColumnNames(List *dst, List *src) -{ - ListCell *dst_item; - ListCell *src_item; - - src_item = list_head(src); - - foreach(dst_item, dst) - { - TargetEntry *d = (TargetEntry *) lfirst(dst_item); - ColumnDef *s; - - /* junk targets don't count */ - if (d->resjunk) - continue; - - /* fewer ColumnDefs than target entries is OK */ - if (src_item == NULL) - break; - - s = (ColumnDef *) lfirst(src_item); - src_item = lnext(src_item); - - d->resname = pstrdup(s->colname); - } - - /* more ColumnDefs than target entries is not OK */ - if (src_item != NULL) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("CREATE TABLE AS specifies too many column names"))); -} - /* * transformUpdateStmt - |