user1583007
user1583007

Reputation: 507

json path in 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

Upvotes: 3

Views: 1796

Answers (1)

wchiquito
wchiquito

Reputation: 16551

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.

Upvotes: 2

Related Questions