I think I am trying something simple, but after hours I just can't get it to work. I have a table which contains a tags column, which is a jsonb array and looks like this:
[
{
"name": "e-commerce",
"weight": 400
},
{
"name": "management",
"weight": 200
},
{
"name": "content management",
"weight": 200
}
]
I now want to write a query which returns the full object to me, when the name matches the search string. So far I came up with this:
SELECT * FROM data
WHERE tags is not null
AND EXISTS(
SELECT FROM data ad WHERE (ad.tags -> 'name' ->> 'education')::text
);
But I get this error:
[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.
I am not sure where I should do a typecast and whether that is really the problem.
I already tried solutions from these threads, but to no avail :-(
tags jsonb[] default'{}'::jsonb[]jsonb[]almost never makes sense. A "plain"jsonbthat includes a real JSON array is a much better choice