SQLite

View Ticket
Login
Ticket Hash: 132994c8b1063bfbe4fc0d7cffba974d0970b9ef
Title: RETURNING old.* seg-faults
Status: Fixed Type: Code_Defect
Severity: Severe Priority: High
Subsystem: Code_Generator Resolution: Fixed
Last Modified: 2021-03-30 19:17:30
Version Found In: 3.35.3
User Comments:
larrybr added on 2021-03-29 22:57:42: (text/x-markdown)
This SQL, applied to :memory: DB,<code>
  CREATE TABLE a (id INTEGER NOT NULL PRIMARY KEY);
  UPDATE a SET id = a.id + 1 FROM (SELECT * FROM a) AS old RETURNING old.*;
</code>
produces a seg-fault at line 99948 of sqlite3.c . 

Reported in forum post: https://sqlite.org/forum/forumpost/cdc28fec1a

larrybr added on 2021-03-29 23:40:47: (text/x-markdown)
Slightly simpler test case (from Keith at the forum):<code>
 create table x(a,b);
 create table y(c,d);
 update x set a=c from y where b=d returning *;
</code>

larrybr added on 2021-03-29 23:55:58: (text/x-markdown)
Strike that final repro update. Both of these seg-fault:<code>
  update x set a=c from y where b=d returning x.\*;
  update x set a=c from y where b=d returning y.\*;
</code>. And, interestingly, this does not:<code>
  update x set a=c from y where b=d returning x.a, y.d;
</code>, instead producing: "Error: no such column: y.d".
(All lifted from Keith's post.)

drh added on 2021-03-30 00:47:59: (text/x-markdown)
The FROM clause is not required.  Any RETURNING that contains the form
"table.*" seems to cause the problem.  Example:

> ~~~
CREATE TABLE t1(x);
INSERT INTO t1 VALUE(1) RETURNING t1.*;
~~~