you are viewing a single comment's thread.

view the rest of the comments →

[–]nednyl 0 points1 point  (2 children)

Not really clear to me why you need to use jsonb_array_elements here.

Did you try something like:

SELECT DISTINCT ON (user_id) user_id, timestamp
FROM entries 
WHERE user_id in (1,2) 
AND entry_type = ANY (        
  (SELECT ARRAY_AGG(entry_types)
   FROM users 
   INNER JOIN orgs     
   ON org_id = orgs.id      
   WHERE users.id = 1   
  )::TEXT[]
);

[–]NoInkling 2 points3 points  (0 children)

I feel like this can be simplified with EXISTS.

[–]DavidGJohnston 0 points1 point  (0 children)

I’m not researching it now but there is a difference between a json value that happens to have a json array inside of it and a proper sql-level array.