Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb145fd

Browse files
committed
Fix dumping of outer joins with empty qual lists.
Normally, a JoinExpr would have empty "quals" only if it came from CROSSJOIN syntax. However, it's possible to get to this state by specifyingNATURAL JOIN between two tables with no common column names, and theremight be other ways too. The code previously printed no ON clause if"quals" was empty; that's right for CROSS JOIN but syntactically invalidif it's some type of outer join. Fix by printing ON TRUE in that case.This got broken by commit2ffa740, which stopped using NATURAL JOINsyntax in ruleutils output due to its brittleness in the face ofcolumn 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
1 parent3cb29c4 commiteb145fd

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10082,6 +10082,11 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
1008210082
if (!PRETTY_PAREN(context))
1008310083
appendStringInfoChar(buf,')');
1008410084
}
10085+
elseif (j->jointype!=JOIN_INNER)
10086+
{
10087+
/* If we didn't say CROSS JOIN above, we must provide an ON */
10088+
appendStringInfoString(buf," ON TRUE");
10089+
}
1008510090

1008610091
if (!PRETTY_PAREN(context)||j->alias!=NULL)
1008710092
appendStringInfoChar(buf,')');

‎src/test/regress/expected/create_view.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,35 @@ select pg_get_viewdef('tt20v', true);
16481648
CAST((1 + 2)::bigint AS bigint) i8(i8);
16491649
(1 row)
16501650

1651+
-- corner cases with empty join conditions
1652+
create view tt21v as
1653+
select * from tt5 natural inner join tt6;
1654+
select pg_get_viewdef('tt21v', true);
1655+
pg_get_viewdef
1656+
----------------------
1657+
SELECT tt5.a, +
1658+
tt5.b, +
1659+
tt5.cc, +
1660+
tt6.c, +
1661+
tt6.d +
1662+
FROM tt5 +
1663+
CROSS JOIN tt6;
1664+
(1 row)
1665+
1666+
create view tt22v as
1667+
select * from tt5 natural left join tt6;
1668+
select pg_get_viewdef('tt22v', true);
1669+
pg_get_viewdef
1670+
-----------------------------
1671+
SELECT tt5.a, +
1672+
tt5.b, +
1673+
tt5.cc, +
1674+
tt6.c, +
1675+
tt6.d +
1676+
FROM tt5 +
1677+
LEFT JOIN tt6 ON TRUE;
1678+
(1 row)
1679+
16511680
-- clean up all the random objects we made above
16521681
set client_min_messages = warning;
16531682
DROP SCHEMA temp_view_test CASCADE;

‎src/test/regress/sql/create_view.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,16 @@ select * from
559559
cast(1+2as int8)as i8;
560560
select pg_get_viewdef('tt20v', true);
561561

562+
-- corner cases with empty join conditions
563+
564+
createviewtt21vas
565+
select*from tt5 naturalinner join tt6;
566+
select pg_get_viewdef('tt21v', true);
567+
568+
createviewtt22vas
569+
select*from tt5natural left join tt6;
570+
select pg_get_viewdef('tt22v', true);
571+
562572
-- clean up all the random objects we made above
563573
set client_min_messages= warning;
564574
DROPSCHEMA temp_view_test CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp