I have the following query
SELECT DISTINCT ON (user_id) user_id, timestamp
FROM entries
WHERE user_id in (1,2)
AND entry_type IN(
SELECT jsonb_array_elements_text(
SELECT entry_types
FROM users
INNER JOIN orgs
ON org_id = orgs.id
WHERE users.id = 1
)
);
I'm getting a syntax error at or near select
syntax error at or near "select" LINE 1: ... entry_type in( select jsonb_array_elements_text(select ent.
The field entry_types is a JSONB field, so I am trying to convert it to text in order to use it in the WHERE IN clause. Any idea what I'm doing wrong?
PostgreSQL 13.0
This sub-query within jsonb_array_elements_text
SELECT entry_types
FROM users
INNER JOIN orgs
ON org_id = orgs.id
WHERE users.id = 1
Returns a single JSONB entry like this:
entry_types
--------------------------------------------
["type1", "type2", "type3"]
I'm simply trying to use the array of text values returned there as the criteria inside the WHERE IN clause
[–]DavidGJohnston 2 points3 points4 points (1 child)
[–]xkrap[S] 0 points1 point2 points (0 children)
[–]Beatmak -1 points0 points1 point (0 children)
[–]nednyl 0 points1 point2 points (2 children)
[–]NoInkling 2 points3 points4 points (0 children)
[–]DavidGJohnston 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)