mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +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:
@@ -3291,7 +3291,7 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
|
||||
foreach(rt, qry->rtable)
|
||||
{
|
||||
RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
|
||||
char *rtename;
|
||||
char *rtename = rte->eref->aliasname;
|
||||
|
||||
++i;
|
||||
if (!rte->inFromCl)
|
||||
@@ -3302,15 +3302,22 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
|
||||
* name and needs to be skipped (otherwise it might hide a
|
||||
* base relation with the same name), except if it has a USING
|
||||
* alias, which *is* visible.
|
||||
*
|
||||
* Subquery and values RTEs without aliases are never visible
|
||||
* as relation names and must always be skipped.
|
||||
*/
|
||||
if (rte->rtekind == RTE_JOIN && rte->alias == NULL)
|
||||
if (rte->alias == NULL)
|
||||
{
|
||||
if (rte->join_using_alias == NULL)
|
||||
if (rte->rtekind == RTE_JOIN)
|
||||
{
|
||||
if (rte->join_using_alias == NULL)
|
||||
continue;
|
||||
rtename = rte->join_using_alias->aliasname;
|
||||
}
|
||||
else if (rte->rtekind == RTE_SUBQUERY ||
|
||||
rte->rtekind == RTE_VALUES)
|
||||
continue;
|
||||
rtename = rte->join_using_alias->aliasname;
|
||||
}
|
||||
else
|
||||
rtename = rte->eref->aliasname;
|
||||
|
||||
if (strcmp(rtename, thisrel->relname) == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user