Skip to content

UPDATE RETURNING reflects AFTER trigger modifications #5492

@LeMikaelF

Description

@LeMikaelF

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions