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

Commit41ada83

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 parent0e8448b commit41ada83

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
@@ -9428,6 +9428,11 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
94289428
if (!PRETTY_PAREN(context))
94299429
appendStringInfoChar(buf,')');
94309430
}
9431+
elseif (j->jointype!=JOIN_INNER)
9432+
{
9433+
/* If we didn't say CROSS JOIN above, we must provide an ON */
9434+
appendStringInfoString(buf," ON TRUE");
9435+
}
94319436

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

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

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

1593+
-- corner cases with empty join conditions
1594+
create view tt21v as
1595+
select * from tt5 natural inner join tt6;
1596+
select pg_get_viewdef('tt21v', true);
1597+
pg_get_viewdef
1598+
----------------------
1599+
SELECT tt5.a, +
1600+
tt5.b, +
1601+
tt5.cc, +
1602+
tt6.c, +
1603+
tt6.d +
1604+
FROM tt5 +
1605+
CROSS JOIN tt6;
1606+
(1 row)
1607+
1608+
create view tt22v as
1609+
select * from tt5 natural left join tt6;
1610+
select pg_get_viewdef('tt22v', true);
1611+
pg_get_viewdef
1612+
-----------------------------
1613+
SELECT tt5.a, +
1614+
tt5.b, +
1615+
tt5.cc, +
1616+
tt6.c, +
1617+
tt6.d +
1618+
FROM tt5 +
1619+
LEFT JOIN tt6 ON TRUE;
1620+
(1 row)
1621+
15931622
-- clean up all the random objects we made above
15941623
set client_min_messages = warning;
15951624
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
@@ -531,6 +531,16 @@ select * from
531531
cast(1+2as int8)as i8;
532532
select pg_get_viewdef('tt20v', true);
533533

534+
-- corner cases with empty join conditions
535+
536+
createviewtt21vas
537+
select*from tt5 naturalinner join tt6;
538+
select pg_get_viewdef('tt21v', true);
539+
540+
createviewtt22vas
541+
select*from tt5natural left join tt6;
542+
select pg_get_viewdef('tt22v', true);
543+
534544
-- clean up all the random objects we made above
535545
set client_min_messages= warning;
536546
DROPSCHEMA temp_view_test CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp