-
Notifications
You must be signed in to change notification settings - Fork 739
Open
Description
Description
When an AFTER UPDATE trigger modifies the same row, UPDATE RETURNING sees the trigger's modifications instead of the UPDATE's own values. INSERT RETURNING correctly shows pre-trigger values.
Reproducer
CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER, c TEXT);
CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
UPDATE t1 SET c = 'trigger_modified' WHERE a = NEW.a;
END;
INSERT INTO t1 VALUES(1, 10, 'original');
UPDATE t1 SET b = 20 WHERE a = 1 RETURNING *;
-- Turso: 1|20|trigger_modified
-- SQLite: 1|20|original
-- INSERT RETURNING correctly shows pre-trigger values:
CREATE TABLE t2(a INTEGER PRIMARY KEY, b INTEGER, c TEXT);
CREATE TRIGGER t2_ai AFTER INSERT ON t2 BEGIN
UPDATE t2 SET c = 'trigger_set' WHERE a = NEW.a;
END;
INSERT INTO t2 VALUES(1, 10, 'original') RETURNING *;
-- Turso: 1|10|original (correct)
-- SQLite: 1|10|original (correct)Per SQLite documentation: "The values emitted by the RETURNING clause are the values as seen by the top-level DELETE, INSERT, or UPDATE statement and do not reflect any subsequent value changes made by triggers. Thus, if the database includes AFTER triggers that modifies some of the values of each row inserted or updated, the RETURNING clause emits the original values that are computed before those triggers run."
This issue brought to you by Mikaël and Claude Code.
Reactions are currently unavailable