Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json path in mariadb

Tags:

mysql

mariadb

currently using mysql 5.7 I can execute the following query accessing a json field in the database:

select myData->'$[0].dataflow' from flowtable limit 1;

If I try the same query on MariaDB it does not work, is there any solution to this problem? I thought MariaDB was fully compatible with mysql and what would it be the correspondent MariaDB syntax?

cheers

like image 252
user1583007 Avatar asked Feb 28 '26 17:02

user1583007


1 Answers

In MySQL, JSON_EXTRACT() was added in 5.7.8:

JSON_EXTRACT(json_doc, path[, path] ...)

...

MySQL 5.7.9 and later supports the -> operator as shorthand for this (JSON_EXTRACT()) function ...

...

In MariaDB (starting with 10.2.3) use JSON_EXTRACT() function, since -> operator is not currently implemented.

MySQL:

SELECT `myData` -> '$[0].dataflow'
FROM `flowtable`
LIMIT 1;

MySQL and MariaDB:

SELECT JSON_EXTRACT(`myData`, '$[0].dataflow')
FROM `flowtable`
LIMIT 1;

See, MySQL db-fiddle and MariaDB dbfiddle.

like image 109
wchiquito Avatar answered Mar 02 '26 07:03

wchiquito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!