简体   繁体   中英

How to use json column in the WHERE clause as a condition

The question is stated in the title and below is an example of the data

insert into table A values('a','b', {'key':'value'});

And I would like to be able to select this row based on the key-value pair using the WHERE clause. How can I do that?

Use JSON_VALUE :

SELECT t.*
FROM tableA t
WHERE JSON_VALUE(col3, '$.key') LIKE 'some_value'

This assumes that the column which contains the JSON value {'key':'value'} is called col3 .

If you are using PostgreSQL then use below query

select * from table_name where column_name->>'key_name' = 'value_name';

Here is solution that's work for me:

column_name->'$.key'

Tested with mysql server 5.7.27

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM