我想在postgreSql中使用表中json对象的where where条件。我需要如何做到这一点:例如:我有一张桌子'测试'它有三列名称(varchar),url(varchar),更多(json)。我需要检索css21Colors = Purple的日期。 more是json类型,下面是更多字段的值。
请让我知道查询的语法应该是什么?
more = {"colorTree":{"Purple":[{"Spanish Violet":"#522173"}],
"Brown":[{"Dark Puce":"#4e3347"}],"White":[{"White":"#ffffff"}],
"Black":[{"Eerie Black":"#1d0d27"}],"Gray":[{"Rose Quartz":"#a091a4"}]},
"sizeoutscount":0,"css21Colors":{"Purple":69,"Brown":5,"White":4,"Black":17,"Gray":3},
"sizeins": [],"sizeinscount":0,"sizeouts":[],"allsizes":["8","10","16"],
"css3Colors": {"Rose Quartz":3,"White":4,"Dark Puce":5,"Eerie Black":17,"Spanish
Violet":69},"hexColors":{"#522173":69,"#4e3347":5,"#ffffff":4,"#1d0d27":17,"#a091a4":3}}
答案 0 :(得分:1)
SELECT more->'css21Colors'->'Purple' FROM test;
此外,您只能查询包含该密钥的行。
SELECT
more->'css21Colors'->'Purple'
FROM
test
WHERE
(more->'css21Colors')::jsonb ? 'Purple';
请注意切换到jsonb
数据类型。