dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.41k stars 488 forks source link

Deprecated := assignment syntax in UPDATE queries causes syntax error in Dolt #8011

Closed arvidfm closed 1 month ago

arvidfm commented 1 month ago

Though the syntax is deprecated, in MySQL you can currently use := in e.g. UPDATE (and I believe INSERT) statements to generate a sequence. For example, if you have a table when you want to set a tbl.ind column to be a unique index, ordered by when the entry was created, you could do something like this:

SET @myvar = 0;

UPDATE tbl SET ind = (@myvar := @myvar + 1)
ORDER BY created_date;

This is currently a syntax error in Dolt.

Note that this syntax has been deprecated in favour of using window functions instead, and will be removed in a future version of MySQL, so implementing this would only be of interest for the sake of compatibility with existing queries.

Standalone MWE:

DROP TABLE IF EXISTS my_tbl;

CREATE TABLE my_tbl(a INT);
INSERT INTO my_tbl () VALUES (), (), (), ();
SET @myvar = 5;
UPDATE my_tbl SET a = (@myvar := @myvar + 1);

DROP TABLE my_tbl;
timsehn commented 1 month ago

Our standard response to "deprecated in the latest MySQL but still works" is to say only if you really need it. Can you work around this one? We would hate to implement it and then have to tear it out. We don't track deprecated MySQL sytax very well.

arvidfm commented 1 month ago

A year ago I would have said it was a blocker, since it's the only syntax that's compatible with both MySQL 5.7 and 8.x, but with 5.7 being EOL and us not supporting it anymore, we need to be porting our queries over to use window functions anyway. So as far as our use case goes at least, this is not a concern, and I only created this issue for completeness' sake.

timsehn commented 1 month ago

OK. I'll close as won't fix. Thanks for all the issues and great repros.