Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL v8.0.13 Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release

Tags:

sql

mysql

Executing the following query in MySQL v8.0.13 results in this error:

0 row(s) affected, 1 warning(s): 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Please set variables in separate statements instead.

SET @i = -1;

UPDATE `tb_test`
SET `order` = (@i := @i + 1)
ORDER BY `order` ASC;

Any suggestions on how to set the variables in a separate statement?

like image 420
Philip Ferreira Avatar asked Nov 26 '18 03:11

Philip Ferreira


1 Answers

This is really a shot in the dark (never used mySQL), but checking the docs it says:

"Support for setting user variables in statements other than SET was deprecated in MySQL 8.0.13. This functionality is subject to removal in MySQL 9.0."

(Emphasis mine).

So maybe the problem is that you increment @i without using SET? Can you rewrite this with an explicit SET and see if it helps?

like image 153
p.marino Avatar answered Nov 04 '22 08:11

p.marino