Skip to content

Read a table-qualified column of the changed row in UPDATE and DELETE to close #2814 and #2792 - #2991

Open
mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2814-update-qualified-column
Open

mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2814-update-qualified-column

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Closes #2814
Closes #2792

UPDATE t SET u = t.u + 1 and UPDATE t SET u = 0 WHERE t.u > 1 threw TypeError: ... evaluating 'r['t']['u']'. UPDATE and DELETE compiled SET and WHERE against the row itself, so a column named with its table looked for a key t in the row. A correlated subquery that names the changed table (#2792) failed the same way.

  • src/74update.js and src/72delete.js now compile these expressions against a scope that holds the row under the table name, as a SELECT does. t.u and u read the same value, and a subquery gets that scope as its outer row.
  • A subquery in UPDATE or DELETE that reads the changed table by name is now marked correlated, so it runs again for each row. Without this, the NOT IN example of A correlated subquery in the WHERE of UPDATE or DELETE throws a TypeError #2792 reused the result of the first row and updated E2 too. A subquery that has the same table in its own FROM is not marked and keeps its cached result.

test/test2814.js covers a qualified column in SET and WHERE, a bare column, DELETE, parameters, the UPDATE ... NOT IN and DELETE ... EXISTS examples of #2792, and a subquery over the same table. The tests fail on develop and pass with the change. yarn test-only gives 2557 pass. The only failures are the 5 Test 418 cases that load data from the internet, and they fail the same way on develop in my environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants