在JSON数组中查找元素的索引
CREATE TABLE tracks (id SERIAL, artists JSON);INSERT INTO tracks (id, artists) VALUES (1, '[{"name": "blink-182"}]');INSERT INTO tracks (id, artists) VALUES (2, '[{"name": "The Dirty Heads"}, {"name": "Louis Richards"}]');
SELECT * FROM tracks WHERE 'ARTIST NAME' IN (SELECT value->>'name' FROM json_array_elements(artists))
SELECT * FROM tracks WHERE 'The Dirty Heads' IN (SELECT value->>'name' FROM json_array_elements(artists))
names_as_array(artists)
'ARTIST NAME' = ANY names_as_array(artists)
catspeake
相关分类