Skip to content

sql: mutations in statement sources don't work properly with limits #20732

@jordanlewis

Description

@jordanlewis
root@:26257/test> create table a (a int);
CREATE TABLE
root@:26257/test> insert into a values(1),(2);
INSERT 2
root@:26257/test> select * from [delete from a returning a] limit 1;
+---+
| a |
+---+
| 1 |
+---+
(1 row)
root@:26257/test> select * from [delete from a returning a] limit 2;
+---+
| a |
+---+
| 1 |
| 2 |
+---+
(2 rows)
root@:26257/test> select * from a;
+---+
| a |
+---+
| 1 |
| 2 |
+---+
(2 rows)

As you can see, the inner delete never gets executed.

Without a limit, or with an offset, this seems to work properly:

root@:26257/test> select * from [delete from a returning a] offset 1;
+---+
| a |
+---+
| 2 |
+---+
(1 row)
root@:26257/test> select * from a;
+---+
| a |
+---+
+---+
(0 rows)

Same problem exists with insert:

root@:26257/test> select * from [insert into a values(1) returning a] limit 1;
+---+
| a |
+---+
| 1 |
+---+
(1 row)
root@:26257/test> select * from a;
+---+
| a |
+---+
+---+
(0 rows)

cc @knz

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions