Hey! I’ve got a question that I’m a bit stumped on...
# help
f
Hey! I’ve got a question that I’m a bit stumped on. My end goal is to query a field based on the value of an item inside an array -- nested within a JSONB object. Here’s an example: Table candidates
Copy code
| uuid |                       data                       |
-----------------------------------------------------------
| cafe | {"foo": "bar", "applications": [{"job": "baz"}]} |
So far this plain SQL query works:
Copy code
SELECT c.uuid, c.data
FROM candidate as c
WHERE c.data->'applications' @> '[{"job": "baz"}]'::jsonb
as does this:
Copy code
SELECT c.uuid, c.data
FROM candidate as c
WHERE EXISTS ( SELECT TRUE FROM jsonb_array_elements(data->'applications') AS apps WHERE apps->>'job' IN ('baz') )` but I’m pretty stumped about translating this to a Supabase query. The PostgREST docs do mention that these JSON operations should be possible, but it’s not clear how to safely construct this query. The only thing that comes to mind is something like "'[{\"job\": \"" + job_id_here "\"}]'" 😦
n
Hello @fig.newton! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Want to unsubscrie from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! Done using the thread? Click the button below to archive it.