[MDEV-17018] JSON_SEARCH and User-Defined Variables Created: 2018-08-19  Updated: 2018-09-12  Resolved: 2018-09-12

Status: Closed
Project: MariaDB Server
Component/s: JSON, Variables
Affects Version/s: 10.2.16, 10.3.9, 10.2, 10.3
Fix Version/s: 10.2.18

Type: Bug Priority: Major
Reporter: William Chiquito Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

Unexpected behavior when searching with a user-defined variable.

MariaDB (see dbfiddle):

MariaDB [(none)]> SELECT VERSION();
+------------------------------------------+
| VERSION()                                |
+------------------------------------------+
| 10.3.9-MariaDB-1:10.3.9+maria~bionic-log |
+------------------------------------------+
1 row in set (0.000 sec)
 
MariaDB [(none)]> SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]',
    ->     @`value` := 'AB';
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [(none)]> SELECT JSON_SEARCH(@`json`, 'one', @`value`);
+---------------------------------------+
| JSON_SEARCH(@`json`, 'one', @`value`) |
+---------------------------------------+
| NULL                                  |
+---------------------------------------+
1 row in set, 1 warning (0.000 sec)
 
MariaDB [(none)]> SHOW WARNINGS;
+---------+------+---------------------------------------------------------------------------------+
| Level   | Code | Message                                                                         |
+---------+------+---------------------------------------------------------------------------------+
| Warning | 4038 | Syntax error in JSON text in argument 1 to function 'json_search' at position 1 |
+---------+------+---------------------------------------------------------------------------------+
1 row in set (0.000 sec)
 
MariaDB [(none)]> SELECT JSON_SEARCH(JSON_UNQUOTE(@`json`), 'one', @`value`);
+-----------------------------------------------------+
| JSON_SEARCH(JSON_UNQUOTE(@`json`), 'one', @`value`) |
+-----------------------------------------------------+
| "$[2].C"                                            |
+-----------------------------------------------------+
1 row in set (0.000 sec)

MySQL (see dbfiddle):

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.12    |
+-----------+
1 row in set (0.000 sec)
 
mysql> SET @`json` := '["A", [{"B": "1"}], {"C": "AB"}, {"D": "BC"}]',
    ->     @`value` := 'AB';
Query OK, 0 rows affected (0.000 sec)
 
mysql> SELECT JSON_SEARCH(@`json`, 'one', @`value`);
+---------------------------------------+
| JSON_SEARCH(@`json`, 'one', @`value`) |
+---------------------------------------+
| "$[2].C"                              |
+---------------------------------------+
1 row in set (0.000 sec)
 
mysql> SHOW WARNINGS;
Empty set (0.000 sec)



 Comments   
Comment by Alice Sherepa [ 2018-08-20 ]

Thanks for the report! Repeatable on MariaDB 10.2, 10.3

Comment by Alexey Botchkov [ 2018-09-12 ]

http://lists.askmonty.org/pipermail/commits/2018-September/012919.html

Generated at Thu Feb 08 08:33:17 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.