Skip to content

UPDATE and DELETE with an IN subquery reuse the subquery result of the first run on later runs #3137

Backlog

Description

@mathiasrw
alasql('CREATE TABLE u (x INT); INSERT INTO u VALUES (1),(2)');
alasql('CREATE TABLE t (a INT, b INT); INSERT INTO t VALUES (1,0),(2,0),(3,0)');
const upd = 'UPDATE t SET b = b + 1 WHERE a IN (SELECT x FROM u WHERE x <= ?)';
alasql(upd, [1]);
alasql(upd, [2]);
alasql('CREATE TABLE d (a INT); INSERT INTO d VALUES (1),(2),(3)');
const del = 'DELETE FROM d WHERE a IN (SELECT x FROM u WHERE x <= ?)';
alasql(del, [1]);
alasql(del, [2]);
alasql('SELECT * FROM t; SELECT * FROM d');

The second UPDATE changes 1 row and the second DELETE deletes none, so t is (1, 2), (2, 0), (3, 0) and d is 2, 3.

SQLite changes 2 rows and deletes 1 row, so t is (1, 2), (2, 1), (3, 0) and d is 3.

Fixed by #2667.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions