SQLite User Forum

SQLITE_ENABLE_UPDATE_DELETE_LIMIT might make WHERE mandatory before RETURNING in UPDATE
Login

SQLITE_ENABLE_UPDATE_DELETE_LIMIT might make WHERE mandatory before RETURNING in UPDATE

(1) By anonymous on 2023-10-17 03:51:29 [source]

This bug report is derived from inspecting the syntax diagram. There is no path to returning-clause without going through WHERE expr.

This might be a documentation-only bug, since the diagrams seem to be manually built and I don't have a copy of sqlite that is both new enough to support RETURNING and was compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT.

Test code if relevant:

DROP TABLE IF EXISTS dummy;
CREATE TABLE dummy (x INT);
INSERT INTO dummy VALUES (1), (2), (3);
UPDATE dummy SET x=-x WHERE 1 RETURNING x;
UPDATE dummy SET x=-x RETURNING x LIMIT 1;
SELECT * FROM dummy;

If you get a syntax error on the first RETURNING, your sqlite is too old.

If you get a syntax error on the LIMIT, your sqlite was compiled without SQLITE_ENABLE_UPDATE_DELETE_LIMIT.

If you get a syntax error on the second RETURNING, this bug affects code too.

If you get no syntax errors, then it is a documentation-only bug.

The syntax diagram for DELETE ... RETURNING ... LIMIT is not affected.

(mandatory note that WHERE should always be mandatory because we are all dummies)

(2) By Larry Brasfield (larrybr) on 2023-10-17 22:12:58 in reply to 1 [link] [source]

... This might be a documentation-only bug ...

Yes, it was. It is fixed in the doc repo now. Thanks for reporting this.

(3) By Richard Hipp (drh) on 2023-10-17 22:49:44 in reply to 2 [link] [source]

I cherry-picked Larry's patch onto the 3.43 branch, rebuilt the website, and pushed it to the server. So the syntax diagram should now be correct.