aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-09-13 13:54:24 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-09-13 13:54:24 -0400
commita4c35ea1c2f05dd5b56739fcd0dc36a4870ea0c0 (patch)
tree9a3f91f3835e33ea50c6fbf4442260c9b257167e /src/backend/parser/parse_utilcmd.c
parent445a38aba26cb80a4506af2248e3b425f795a099 (diff)
downloadpostgresql-a4c35ea1c2f05dd5b56739fcd0dc36a4870ea0c0.tar.gz
postgresql-a4c35ea1c2f05dd5b56739fcd0dc36a4870ea0c0.zip
Improve parser's and planner's handling of set-returning functions.
Teach the parser to reject misplaced set-returning functions during parse analysis using p_expr_kind, in much the same way as we do for aggregates and window functions (cf commit eaccfded9). While this isn't complete (it misses nesting-based restrictions), it's much better than the previous error reporting for such cases, and it allows elimination of assorted ad-hoc expression_returns_set() error checks. We could add nesting checks later if it seems important to catch all cases at parse time. There is one case the parser will now throw error for although previous versions allowed it, which is SRFs in the tlist of an UPDATE. That never behaved sensibly (since it's ill-defined which generated row should be used to perform the update) and it's hard to see why it should not be treated as an error. It's a release-note-worthy change though. Also, add a new Query field hasTargetSRFs reporting whether there are any SRFs in the targetlist (including GROUP BY/ORDER BY expressions). The parser can now set that basically for free during parse analysis, and we can use it in a number of places to avoid expression_returns_set searches. (There will be more such checks soon.) In some places, this allows decontorting the logic since it's no longer expensive to check for SRFs in the tlist --- so I made the checks parallel to the handling of hasAggs/hasWindowFuncs wherever it seemed appropriate. catversion bump because adding a Query field changes stored rules. Andres Freund and Tom Lane Discussion: <24639.1473782855@sss.pgh.pa.us>
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 7a2950e6a92..0670bc24822 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -294,7 +294,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
* overridden if an inherited table has oids.
*/
stmt->options = lcons(makeDefElem("oids",
- (Node *) makeInteger(cxt.hasoids), -1),
+ (Node *) makeInteger(cxt.hasoids), -1),
stmt->options);
}
@@ -483,7 +483,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
makeString(cxt->relation->relname),
makeString(column->colname));
altseqstmt->options = list_make1(makeDefElem("owned_by",
- (Node *) attnamelist, -1));
+ (Node *) attnamelist, -1));
cxt->alist = lappend(cxt->alist, altseqstmt);
@@ -2106,17 +2106,11 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
/*
* transformExpr() should have already rejected subqueries,
- * aggregates, and window functions, based on the EXPR_KIND_ for
- * an index expression.
+ * aggregates, window functions, and SRFs, based on the EXPR_KIND_
+ * for an index expression.
*
- * Also reject expressions returning sets; this is for consistency
- * with what transformWhereClause() checks for the predicate.
* DefineIndex() will make more checks.
*/
- if (expression_returns_set(ielem->expr))
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("index expression cannot return a set")));
}
}
@@ -2594,12 +2588,6 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
def->cooked_default =
transformExpr(pstate, def->raw_default,
EXPR_KIND_ALTER_COL_TRANSFORM);
-
- /* it can't return a set */
- if (expression_returns_set(def->cooked_default))
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("transform expression must not return a set")));
}
newcmds = lappend(newcmds, cmd);