我想做一些简单的事情,但是经过数小时的尝试,我仍然无法使它工作。我有一个表格,其中包含一个标签列,这是一个jsonb数组,看起来像这样:
{"{\"name\": \"e-commerce\", \"weight\": 400}","{\"name\": \"management\", \"weight\": 200}","{\"name\": \"content management\", \"weight\": 200}"}
我现在想写一个查询,当名称与搜索字符串匹配时,返回完整的对象。到目前为止,我想出了以下内容:
SELECT * FROM data
WHERE tags is not null
AND EXISTS(
SELECT FROM data ad WHERE (ad.tags -> 'name' ->> 'education')::text
);
但是我遇到了这个错误:
[42883] ERROR: operator does not exist: jsonb[] -> unknown Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我不确定在哪里进行类型转换以及是否真的是问题所在。
tags jsonb[] default'{}'::jsonb[]
- Gh05djsonb[]
几乎没有意义。包含真正的JSON数组的“普通”jsonb
是一个更好的选择。 - user330315