mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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
This commit is contained in:
@ -403,16 +403,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
|
||||
@ -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 */
|
||||
|
Reference in New Issue
Block a user