diff options
author | Dean Rasheed <dean.a.rasheed@gmail.com> | 2022-07-20 09:29:42 +0100 |
---|---|---|
committer | Dean Rasheed <dean.a.rasheed@gmail.com> | 2022-07-20 09:29:42 +0100 |
commit | bcedd8f5fce0b69970cf0cee7bca560833d05869 (patch) | |
tree | c37888d24735977b7a0463b0277c1cbe459ac69f /src/backend/parser/parse_clause.c | |
parent | 1caf915ff31e91031f0a0b8e1016df2b59d6f9de (diff) | |
download | postgresql-bcedd8f5fce0b69970cf0cee7bca560833d05869.tar.gz postgresql-bcedd8f5fce0b69970cf0cee7bca560833d05869.zip |
Make subquery aliases optional in the FROM clause.
This allows aliases for sub-SELECTs and VALUES clauses in the FROM
clause to be omitted.
This is an extension of the SQL standard, supported by some other
database systems, and so eases the transition from such systems, as
well as removing the minor inconvenience caused by requiring these
aliases.
Patch by me, reviewed by Tom Lane.
Discussion: https://postgr.es/m/CAEZATCUCGCf82=hxd9N5n6xGHPyYpQnxW8HneeH+uP7yNALkWA@mail.gmail.com
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r-- | src/backend/parser/parse_clause.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index c655d188c76..5a18107e799 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -404,16 +404,6 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r) Query *query; /* - * We require user to supply an alias for a subselect, per SQL92. To relax - * this, we'd have to be prepared to gin up a unique alias for an - * unlabeled subselect. (This is just elog, not ereport, because the - * grammar should have enforced it already. It'd probably be better to - * report the error here, but we don't have a good error location here.) - */ - if (r->alias == NULL) - elog(ERROR, "subquery in FROM must have an alias"); - - /* * Set p_expr_kind to show this parse level is recursing to a subselect. * We can't be nested within any expression, so don't need save-restore * logic here. @@ -430,10 +420,14 @@ transformRangeSubselect(ParseState *pstate, RangeSubselect *r) pstate->p_lateral_active = r->lateral; /* - * Analyze and transform the subquery. + * Analyze and transform the subquery. Note that if the subquery doesn't + * have an alias, it can't be explicitly selected for locking, but locking + * might still be required (if there is an all-tables locking clause). */ query = parse_sub_analyze(r->subquery, pstate, NULL, - isLockedRefname(pstate, r->alias->aliasname), + isLockedRefname(pstate, + r->alias == NULL ? NULL : + r->alias->aliasname), true); /* Restore state */ |