Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d7952a

Browse files
deanrasheedpull[bot]
authored andcommitted
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 5f0108d commit 5d7952a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/backend/parser/parse_merge.c

Lines 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

Lines 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

Lines 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)