Bug in integrate MySQL function JSON_SEARCH

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 12:29:15

问题


how i use MySQL function JSON_SEARCH on all values, not only on strings?

All this bug is documented on MySQL emulator: https://www.db-fiddle.com/f/2UdrxqrQ3DeonbKWw3pVVp/0

I have DDL:

CREATE TABLE table_name (
    id int NOT NULL AUTO_INCREMENT,
    json_config JSON,
    PRIMARY KEY (id)
);


INSERT INTO table_name (id,json_config)
VALUES 
  (NULL, '{
    "_id": "60111111111111175b78fe2fa",
    "intestx": 0,
    "codes": [
        48348,
        28923,
        39080
   ],
   "test": 562222222222456
   }'); 

Query #1:

SELECT 
    JSON_SEARCH(json_config, 'all', '%1111%')
FROM table_name;

Result #1:

"$._id" #this is OK

Query #2:

SELECT 
    JSON_SEARCH(json_config, 'all', '%2222%')
FROM table_name;

Result #2:

null # this is bad BUG, because is exist match with $.test

Thank you for your advice on how to search over all values, not only on the string, but also over numbers, etc.

EDIT: I found this bug report on MySQL bugzilla since 2015, but this bug has not been resolved, only update on documentation about function search only on strings... :-D https://bugs.mysql.com/bug.php?id=79233

MySQL probably can't search correctly, only over strings. So I probably can't solve it via SQL (view), but I have to solve it by complex programming of my own logic in the form of PHP + SQL (table)...

I'm not happy about that at all. If you knew any handy PHP component that could do this. By that I mean parse JSON to key, value combinations to create all combinations of list of variables.


回答1:


The bug is only in MySQL. I installed MariaDB and it works properly for me there. So I will use MariaDB and that solves it for me.

EDIT: I cannot make solved flat to own answear... :-) But this is solved for me.



来源:https://stackoverflow.com/questions/65938278/bug-in-integrate-mysql-function-json-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!