sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

UPDATE with SELECT not supported

Open gullij opened this issue 8 years ago • 1 comments

Was using the php-sqllint package (says to report errors here) and got these errors on valid MySQL syntax:

Line 1, col 45 at "(": An expression was expected. Line 1, col 45 at "(": Unexpected token. Line 1, col 46 at "SELECT": A new statement was found, but no delimiter between it and the previous one. Line 1, col 106 at ")": Unexpected token. Line 1, col 108 at "src": Unexpected token. Line 2, col 5 at "SET": A new statement was found, but no delimiter between it and the previous one.

The SQL to generate these errors is similar to this (table, column names and values are different):

UPDATE table1 t1, (SELECT `id` FROM table2 WHERE `unique_val` = 1) src
    SET t1.ref_to_t2 = src.id
    WHERE t1.unique_val = 'unique';

gullij avatar Jul 17 '17 14:07 gullij

Another testcase from #163:

INSERT IGNORE INTO user_role (member_id, role_id) (SELECT id, '4150C5' FROM mem WHERE mem_type='Full' AND email NOT LIKE '%example.com');

If I remove the parenthesis, it's no longer considered an error, ie:

INSERT IGNORE INTO user_role (member_id, role_id) SELECT id, '4150C5' FROM mem WHERE mem_type='Full' AND email NOT LIKE '%example.com';

nijel avatar Aug 10 '17 13:08 nijel