Commit b2b0673e authored by Tom Lane's avatar Tom Lane

When displaying a Var that is a reference to a column of an unnamed join,

try to display it as a reference to the underlying column instead.  This
is a legitimate substitution (it wouldn't be for a named join) and it
fixes some cases where the display would otherwise be ambiguous.  Per
example from Sim Zacks.
parent 3fe70420
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.183 2004/10/17 21:17:27 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.184 2004/10/27 18:09:38 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -2558,6 +2558,29 @@ get_names_for_var(Var *var, deparse_context *context, ...@@ -2558,6 +2558,29 @@ get_names_for_var(Var *var, deparse_context *context,
} }
else if (rte->rtekind == RTE_JOIN) else if (rte->rtekind == RTE_JOIN)
{ {
/*
* If it's an unnamed join, look at the expansion of the alias
* variable. If it's a simple reference to one of the input
* vars then recursively find the name of that var, instead.
* (This allows correct decompiling of cases where there are
* identically named columns on both sides of the join.)
* When it's not a simple reference, we have to just return
* the unqualified variable name (this can only happen with
* columns that were merged by USING or NATURAL clauses).
*/
if (var->varattno > 0)
{
Var *aliasvar;
aliasvar = (Var *) list_nth(rte->joinaliasvars,
var->varattno-1);
if (IsA(aliasvar, Var))
{
get_names_for_var(aliasvar, context,
schemaname, refname, attname);
return;
}
}
/* Unnamed join has neither schemaname nor refname */ /* Unnamed join has neither schemaname nor refname */
*refname = NULL; *refname = NULL;
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment