aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-06-12 19:42:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-06-12 19:43:09 -0400
commitf95d8f81062a7afa00fa034022724734a1ff5e60 (patch)
treee1c5a95227bb4fb61944c2da5fb1a26607d7a573 /src/backend/utils/adt/ruleutils.c
parente23338cec4fb088235f27949c4f298b9738877d9 (diff)
downloadpostgresql-f95d8f81062a7afa00fa034022724734a1ff5e60.tar.gz
postgresql-f95d8f81062a7afa00fa034022724734a1ff5e60.zip
Fix incorrect printing of queries with duplicated join names.
Given a query in which multiple JOIN nodes used the same alias (which'd necessarily be in different sub-SELECTs), ruleutils.c would assign the JOIN nodes distinct aliases for clarity ... but then it forgot to print the modified aliases when dumping the JOIN nodes themselves. This results in a dump/reload hazard for views, because the emitted query is flat-out incorrect: Vars will be printed with table names that have no referent. This has been wrong for a long time, so back-patch to all supported branches. Philip Dubé Discussion: https://postgr.es/m/CY4PR2101MB080246F2955FF58A6ED1FEAC98140@CY4PR2101MB0802.namprd21.prod.outlook.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 54f5cac1e3e..74a18a146d0 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -10245,8 +10245,16 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
/* Yes, it's correct to put alias after the right paren ... */
if (j->alias != NULL)
{
+ /*
+ * Note that it's correct to emit an alias clause if and only if
+ * there was one originally. Otherwise we'd be converting a named
+ * join to unnamed or vice versa, which creates semantic
+ * subtleties we don't want. However, we might print a different
+ * alias name than was there originally.
+ */
appendStringInfo(buf, " %s",
- quote_identifier(j->alias->aliasname));
+ quote_identifier(get_rtable_name(j->rtindex,
+ context)));
get_column_alias_list(colinfo, context);
}
}