Or filtering across embedded resources query construction #3748
-
I have two PostgreSQL tables. Table A:
Table B:
This is a one to many relationship, so there is always one entry in table A which has none, one, or multiple matches in table B. I now need to construct a PostgREST query that gives me all the results when there is an entry for a specified How can I do this? I figured I need https://docs.postgrest.org/en/stable/references/api/resource_embedding.html#or-filtering-across-embedded-resources since I need to join two tables together and then look if either the main resource (Table A) contains that
This gives the error "Column a.b does not exist", since I somehow need the or filtering across embedded resources I guess. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You need to use curl 'http://localhost:3000/a?select=*,b(*)&b.user_id=eq.8d084598-9a33-4766-ab97-b27d86c69759&or=(user_id.eq.8d084598-9a33-4766-ab97-b27d86c69759,b.not.is.null)' It could be read like this: "Get data from the As a follow up, you may want to get the data from the curl 'http://localhost:3000/a?select=*,b(*),bf:b()&bf.user_id=eq.8d084598-9a33-4766-ab97-b27d86c69759&or=(user_id.eq.8d084598-9a33-4766-ab97-b27d86c69759,bf.not.is.null)' |
Beta Was this translation helpful? Give feedback.
You need to use
b.not.is.null
inside theor
and filter theb
table outside of it. Something like this:curl 'http://localhost:3000/a?select=*,b(*)&b.user_id=eq.8d084598-9a33-4766-ab97-b27d86c69759&or=(user_id.eq.8d084598-9a33-4766-ab97-b27d86c69759,b.not.is.null)'
It could be read like this: "Get data from the
a
table, where theuser_id
is8d084598-9a33-4766-ab97-b27d86c69759
or where the filter for theb
embedis not null
".As a follow up, you may want to get the data from the
b
table when theuser_id
is not equal to8d084598-9a33-4766-ab97-b27d86c69759
. The next part of the documentation mentions this, you would need one empty embed to filter and another to retrieve…