jsonb 数组项选择的 where 子句不起作用

问题描述 投票:0回答:1

我试试这个

SELECT elem
FROM jsonb_array_elements('["*", "12/05/2020"]'::jsonb) AS elem
WHERE elem::text != '*';

还有这个

SELECT * FROM (
SELECT elem::text 
FROM jsonb_array_elements('["*", "12/05/2020"]'::jsonb) AS elem
) elems WHERE elem != '*'

还有

SELECT * FROM (
SELECT elem::text 
FROM jsonb_array_elements('["*", "12/05/2020"]'::jsonb) AS elem
) elems WHERE elem::text != '*'

并期待所有情况下的结果

"12/05/2020"
。但是得到
"*", "12/05/2020"

为什么?

postgresql plsql jsonb
1个回答
0
投票

事实上我已经找到答案了:

SELECT elem
FROM jsonb_array_elements('["*", "12/05/2020"]'::jsonb) AS elem
WHERE elem::text != '"*"';

您需要单引号和双引号!

© www.soinside.com 2019 - 2024. All rights reserved.