mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Improve generated column names for cases involving sub-SELECTs.
We'll now use "exists" for EXISTS(SELECT ...), "array" for ARRAY(SELECT ...), or the sub-select's own result column name for a simple expression sub-select. Previously, you usually got "?column?" in such cases. Marti Raudsepp, reviewed by Kyotaro Horiugchi
This commit is contained in:
@ -1610,6 +1610,48 @@ FigureColnameInternal(Node *node, char **name)
|
||||
break;
|
||||
case T_CollateClause:
|
||||
return FigureColnameInternal(((CollateClause *) node)->arg, name);
|
||||
case T_SubLink:
|
||||
switch (((SubLink *) node)->subLinkType)
|
||||
{
|
||||
case EXISTS_SUBLINK:
|
||||
*name = "exists";
|
||||
return 2;
|
||||
case ARRAY_SUBLINK:
|
||||
*name = "array";
|
||||
return 2;
|
||||
case EXPR_SUBLINK:
|
||||
{
|
||||
/* Get column name of the subquery's single target */
|
||||
SubLink *sublink = (SubLink *) node;
|
||||
Query *query = (Query *) sublink->subselect;
|
||||
|
||||
/*
|
||||
* The subquery has probably already been transformed,
|
||||
* but let's be careful and check that. (The reason
|
||||
* we can see a transformed subquery here is that
|
||||
* transformSubLink is lazy and modifies the SubLink
|
||||
* node in-place.)
|
||||
*/
|
||||
if (IsA(query, Query))
|
||||
{
|
||||
TargetEntry *te = (TargetEntry *) linitial(query->targetList);
|
||||
|
||||
if (te->resname)
|
||||
{
|
||||
*name = te->resname;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* As with other operator-like nodes, these have no names */
|
||||
case ALL_SUBLINK:
|
||||
case ANY_SUBLINK:
|
||||
case ROWCOMPARE_SUBLINK:
|
||||
case CTE_SUBLINK:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case T_CaseExpr:
|
||||
strength = FigureColnameInternal((Node *) ((CaseExpr *) node)->defresult,
|
||||
name);
|
||||
|
Reference in New Issue
Block a user