Skip to content

Navigation Menu

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

Appearance settings

Commit f026c16

Browse filesBrowse files
committed
Fix MERGE's test for unreachable WHEN clauses.
The former code would only detect an unreachable WHEN clause if it had an AND condition. Fix, so that unreachable unconditional WHEN clauses are also detected. Back-patch to v15, where MERGE was added. Discussion: https://postgr.es/m/CAEZATCVQ=7E2z4cSBB49jjeGGsB6WeoYQY32NDeSvcHiLUZ=ow@mail.gmail.com
1 parent d952373 commit f026c16
Copy full SHA for f026c16

File tree

3 files changed

+5
-5
lines changed
Filter options

3 files changed

+5
-5
lines changed

‎src/backend/parser/parse_merge.c

Copy file name to clipboardExpand all lines: src/backend/parser/parse_merge.c
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt)
155155
/*
156156
* Check for unreachable WHEN clauses
157157
*/
158-
if (mergeWhenClause->condition == NULL)
159-
is_terminal[when_type] = true;
160-
else if (is_terminal[when_type])
158+
if (is_terminal[when_type])
161159
ereport(ERROR,
162160
(errcode(ERRCODE_SYNTAX_ERROR),
163161
errmsg("unreachable WHEN clause specified after unconditional WHEN clause")));
162+
if (mergeWhenClause->condition == NULL)
163+
is_terminal[when_type] = true;
164164
}
165165

166166
/*

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

Copy file name to clipboardExpand all lines: src/test/regress/expected/merge.out
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ USING source AS s
659659
ON t.tid = s.sid
660660
WHEN MATCHED THEN /* Terminal WHEN clause for MATCHED */
661661
DELETE
662-
WHEN MATCHED AND s.delta > 0 THEN
662+
WHEN MATCHED THEN
663663
UPDATE SET balance = t.balance - s.delta;
664664
ERROR: unreachable WHEN clause specified after unconditional WHEN clause
665665
ROLLBACK;

‎src/test/regress/sql/merge.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/merge.sql
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ USING source AS s
438438
ON t.tid = s.sid
439439
WHEN MATCHED THEN /* Terminal WHEN clause for MATCHED */
440440
DELETE
441-
WHEN MATCHED AND s.delta > 0 THEN
441+
WHEN MATCHED THEN
442442
UPDATE SET balance = t.balance - s.delta;
443443
ROLLBACK;
444444

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.