From eb145fdfea91ee5dc6d7aad0309527f810f7c90a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 20 Jul 2017 11:29:36 -0400 Subject: Fix dumping of outer joins with empty qual lists. Normally, a JoinExpr would have empty "quals" only if it came from CROSS JOIN syntax. However, it's possible to get to this state by specifying NATURAL JOIN between two tables with no common column names, and there might be other ways too. The code previously printed no ON clause if "quals" was empty; that's right for CROSS JOIN but syntactically invalid if it's some type of outer join. Fix by printing ON TRUE in that case. This got broken by commit 2ffa740be, which stopped using NATURAL JOIN syntax in ruleutils output due to its brittleness in the face of column renamings. Back-patch to 9.3 where that commit appeared. Per report from Tushar Ahuja. Discussion: https://postgr.es/m/98b283cd-6dda-5d3f-f8ac-87db8c76a3da@enterprisedb.com --- src/backend/utils/adt/ruleutils.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index d2fb20d5649..23000281bbe 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10082,6 +10082,11 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) if (!PRETTY_PAREN(context)) appendStringInfoChar(buf, ')'); } + else if (j->jointype != JOIN_INNER) + { + /* If we didn't say CROSS JOIN above, we must provide an ON */ + appendStringInfoString(buf, " ON TRUE"); + } if (!PRETTY_PAREN(context) || j->alias != NULL) appendStringInfoChar(buf, ')'); -- cgit v1.2.3