SQLite Forum

Crash when a RETURNING clause refers to a table in UPDATE FROM
Login
That seems to work such that as of [51d5c50b2f] on trunk new and old are no longer recognized -- only columns from the UPDATE/INSERT target.  But expressions and scalar correlates are still permitted.

```
SQLite version 3.36.0 2021-03-31 21:26:50
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table x(x);
sqlite> create table y(x,y);
sqlite> insert into x values (2);
sqlite> insert into y values (2,5);
sqlite> insert into x values (2) returning x, (select y from y where x.x == y.x);
┌───┬────────────────────────────────────┐
│ x │ (select y from y where x.x == y.x) │
├───┼────────────────────────────────────┤
│ 2 │ 5                                  │
└───┴────────────────────────────────────┘
sqlite> insert into x values (45) returning x, sin(radians(x));
┌────┬───────────────────┐
│ x  │  sin(radians(x))  │
├────┼───────────────────┤
│ 45 │ 0.707106781186547 │
└────┴───────────────────┘
```

I note that accessing the old/new tablenames in such a correlate results in crashes ... as shown below (except for INSERT where referencing old returns an appropriate error):

```
sqlite> insert into x values (2) returning x, (select y from y where old.x == y.x);
Error: no such column: old.x
sqlite> insert into x values (2) returning x, (select y from y where new.x == y.x);
*** CRASH ***
update x set x = 1 returning x, (select y from y where y.x == old.x);
*** CRASH ***
update x set x = 1 returning x, (select y from y where y.x == new.x);
*** CRASH ***
```