Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

sql - Bug in integrate MySQL function JSON_SEARCH

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...