mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
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
This commit is contained in:
parent
d952373a98
commit
f026c16a2c
@ -155,12 +155,12 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt)
|
||||
/*
|
||||
* Check for unreachable WHEN clauses
|
||||
*/
|
||||
if (mergeWhenClause->condition == NULL)
|
||||
is_terminal[when_type] = true;
|
||||
else if (is_terminal[when_type])
|
||||
if (is_terminal[when_type])
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("unreachable WHEN clause specified after unconditional WHEN clause")));
|
||||
if (mergeWhenClause->condition == NULL)
|
||||
is_terminal[when_type] = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -659,7 +659,7 @@ USING source AS s
|
||||
ON t.tid = s.sid
|
||||
WHEN MATCHED THEN /* Terminal WHEN clause for MATCHED */
|
||||
DELETE
|
||||
WHEN MATCHED AND s.delta > 0 THEN
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET balance = t.balance - s.delta;
|
||||
ERROR: unreachable WHEN clause specified after unconditional WHEN clause
|
||||
ROLLBACK;
|
||||
|
@ -438,7 +438,7 @@ USING source AS s
|
||||
ON t.tid = s.sid
|
||||
WHEN MATCHED THEN /* Terminal WHEN clause for MATCHED */
|
||||
DELETE
|
||||
WHEN MATCHED AND s.delta > 0 THEN
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET balance = t.balance - s.delta;
|
||||
ROLLBACK;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user