0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mysql8にデーター移行して行数取得でエラー

0
Posted at

以下のソースをMysql5.6で実行してました。

select * from
(select id, @row:=@row+1 as row from tbl_a
where deleted_at is null or deleted_at <= '2019-12-28'
order by deleted_at desc
) st
where id = 12 limit 1

Mysql8で実行するとエラーが出てました。

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'row from tbl_a
where deleted_at is null or deleted_at <= '2019-12-28' at line 2

結論としてはMysql8からROW_NUMBER()関数が追加されて行数を簡単に取得できるようになったようです。だがそれでなんでエラーが出るのか「row」っていう予約語が追加されたのが原因でした。「ROWS」も追加されてますね。

参考:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
参考:https://wpchiraura.xyz/mysql-80-reserved-word-list/

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?