Created
November 28, 2023 00:58
-
-
Save mumbleskates/0430b1c7fb87f5a94b69e6191a57a5bb to your computer and use it in GitHub Desktop.
mysql 8 prepared statement bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table t ( | |
-> id integer primary key, | |
-> val json | |
-> ); | |
Query OK, 0 rows affected (0.04 sec) | |
mysql> insert into t(id, val) values (1, '{"a": 1}'), (2, '{"a": "two"}'); | |
Query OK, 2 rows affected (0.00 sec) | |
Records: 2 Duplicates: 0 Warnings: 0 | |
mysql> prepare stmt from 'select id from t where json_extract(val, ''$."a"'') = ?'; | |
Query OK, 0 rows affected (0.00 sec) | |
Statement prepared | |
mysql> set @a = 'two'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
+----+ | |
| id | | |
+----+ | |
| 2 | | |
+----+ | |
1 row in set (0.00 sec) | |
mysql> set @a = 1; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
+----+ | |
| id | | |
+----+ | |
| 1 | | |
+----+ | |
1 row in set (0.00 sec) | |
mysql> set @a = 'two'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
+----+ | |
| id | | |
+----+ | |
| 2 | | |
+----+ | |
1 row in set (0.00 sec) | |
mysql> select version(); | |
+-----------+ | |
| version() | | |
+-----------+ | |
| 5.7.44 | | |
+-----------+ | |
1 row in set (0.00 sec) | |
mysql> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table t ( | |
-> id integer primary key, | |
-> val json | |
-> ); | |
Query OK, 0 rows affected (0.01 sec) | |
mysql> insert into t(id, val) values (1, '{"a": 1}'), (2, '{"a": "two"}'); | |
Query OK, 2 rows affected (0.00 sec) | |
Records: 2 Duplicates: 0 Warnings: 0 | |
mysql> prepare stmt from 'select id from t where json_extract(val, ''$."a"'') = ?'; | |
Query OK, 0 rows affected (0.00 sec) | |
Statement prepared | |
mysql> set @a = 'two'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
+----+ | |
| id | | |
+----+ | |
| 2 | | |
+----+ | |
1 row in set (0.00 sec) | |
mysql> set @a = 1; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
+----+ | |
| id | | |
+----+ | |
| 1 | | |
+----+ | |
1 row in set (0.00 sec) | |
mysql> set @a = 'two'; | |
Query OK, 0 rows affected (0.00 sec) | |
mysql> execute stmt using @a; | |
Empty set, 2 warnings (0.00 sec) | |
mysql> select version(); | |
+-----------+ | |
| version() | | |
+-----------+ | |
| 8.2.0 | | |
+-----------+ | |
1 row in set (0.00 sec) | |
mysql> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment