You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A correlated subquery in the WHERE of UPDATE or DELETE throws a TypeError #2792
A subquery in the WHERE of UPDATE or DELETE that refers to the table being changed by its name throws a TypeError. The same subquery works in a SELECT.
Seen in the NIST SQL Test Suite run in dml011.sql, dml012.sql and dml158.sql. Reproduced on develop (38bf3c3):
alasql("CREATE TABLE staff (empnum CHAR(3), grade INT, city CHAR(15))");alasql("INSERT INTO staff VALUES ('E1', 12, 'Deale'), ('E2', 10, 'Vienna'), ('E3', 13, 'Vienna')");alasql("CREATE TABLE works (empnum CHAR(3), pnum CHAR(3), hours INT)");alasql("INSERT INTO works VALUES ('E1', 'P1', 40), ('E2', 'P1', 20)");alasql('SELECT empnum FROM staff WHERE staff.empnum NOT IN (SELECT works.empnum FROM works WHERE staff.empnum = works.empnum)');// [{empnum: 'E3'}]alasql('UPDATE staff SET grade = 10 * staff.grade WHERE staff.empnum NOT IN (SELECT works.empnum FROM works WHERE staff.empnum = works.empnum)');// TypeError: undefined is not an object (evaluating 'r['staff']['empnum']')alasql("DELETE FROM works WHERE EXISTS (SELECT * FROM staff WHERE staff.empnum = works.empnum AND staff.city = 'Vienna')");// TypeError: undefined is not an object (evaluating 'p['works']['empnum']')
Expected: the UPDATE changes 1 row (E3 gets grade 130), and the DELETE removes 1 row (E2).
Breaking?
No. Today both throw.
Related: #2644 (correlated subquery with an unqualified outer column), #2632.
A simpler case throws the same error, without a subquery: a table-qualified column anywhere in UPDATE (UPDATE t SET u = t.u + 1). Filed as #2814 from the PostgreSQL regression tests; fixing that is likely to fix this one too.
Activity
mathiasrw commentedon Oct 21, 2026
A simpler case throws the same error, without a subquery: a table-qualified column anywhere in
UPDATE(UPDATE t SET u = t.u + 1). Filed as #2814 from the PostgreSQL regression tests; fixing that is likely to fix this one too.mateuscmtropical commentedon Nov 11, 2026
Hi, I'd like to work on this one, together with #2814 (same cause).
mateuscmtropical commentedon Nov 11, 2026
Hi, I've opened a PR for this: #2991