SQLのブロックコメントのネストについて軽く調べてみた(PostgreSQL, MySQL, SQLite3)

前回(SQLのブロックコメント終端がバックスラッシュエスケープできるか軽く調べてみた(PostgreSQL, MySQL, SQLite3))のを調べていたときに PostgreSQL のドキュメントに

これらのブロックコメントはC言語とは異なり、標準SQLで規定されているように入れ子にすることができます。

と書かれているのを見かけ、へーと思って MySQL、SQLite3 での対応状況を調べてみた。前回と同様に実際に動かして挙動を見ただけです。

結果

PostgreSQL はドキュメントに書かれている通りネスト可。
MySQL、SQLite3 では不可。

PostgreSQL

$ docker run -d --rm -v $(pwd):/work --name postgres postgres:10.5
973208008fe3ef5d12f4629507a55107802583167ad8511852965e42d0595a37
--------------------------------

$ docker exec -it postgres psql -U postgres
psql (10.5 (Debian 10.5-1.pgdg90+1))
Type "help" for help.

postgres=# select /* /* */ */ 1;
 ?column? 
----------
        1
(1 row)

postgres=# 

MySQL

$ docker run -d --rm --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.7.23
d787f3142d10a93f461e6ff420d5304dbd02e46f76203a107ebe4fc5fe5ab401
--------------------------------

$ docker exec -it mysql /usr/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select /* /* */ */ 1;
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 '/ 1' at line 1
mysql> 

SQLite3

$ sqlite3
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> select /* /* */ */ 1;
Error: near "/": syntax error
sqlite>