diff options
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 3833ee2ee2f..bb0fc2a1794 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * 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. * @@ -2558,6 +2558,29 @@ get_names_for_var(Var *var, deparse_context *context, } 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 */ *refname = NULL; } |