-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Related and/or
conditions
#2563
Comments
Having the
I'd like to get the Keeping the shape of our query, this could be done like: WITH pgrst_source AS (
SELECT
"test"."client".*
FROM "test"."client"
LEFT JOIN LATERAL (
SELECT json_agg("client_clientinfo_1") AS "client_clientinfo_1"
FROM (
SELECT
"clientinfo_1".*
FROM "test"."clientinfo" AS "clientinfo_1"
WHERE
"clientinfo_1"."clientid" = "test"."client"."id" AND
"clientinfo_1"."other" LIKE '%Main%'
) AS "client_clientinfo_1"
) AS "client_clientinfo_1" ON TRUE
LEFT JOIN LATERAL (
SELECT json_agg("client_contact_1") AS "client_contact_1"
FROM (
SELECT "contact_1".*
FROM "test"."contact" AS "contact_1"
WHERE
"contact_1"."clientid" = "test"."client"."id" AND
"contact_1"."name" LIKE '%Tabby%'
) AS "client_contact_1"
) AS "client_contact_1" ON TRUE
WHERE
"client_clientinfo_1" IS NOT NULL OR
"client_contact_1" IS NOT NULL
)
SELECT coalesce(json_agg(_postgrest_t), '[]')::character varying AS body
FROM ( SELECT * FROM pgrst_source ) _postgrest_t;
body
------------------------------
[{"id":1,"name":"Walmart"}, +
{"id":2,"name":"Target"}] Which could be expressed in the URL as: GET /client?select=*,clientinfo(),contact()&clientinfo.other=like.*Main*&contact.name=like.*Tabby*&or=(clientinfo.not.is.null,contact.not.is.null) So the good news is that basically we only need to support doing |
Reopening. It's a bit inconvenient(also unclear) to type the Related conditions would be more clear as per the original idea above. So I think we could translate this: GET /projects?select=name,clients(*)&clients(id)=eq.1 To: GET /projects?select=name,clients(*)&clients.id=eq.1&clients=not.is.null
GET /client?select=*,clientinfo(),contact()&or=(clientinfo(other).like.*Main*,contact(name).like.*Tabby*) Then translated to GET /client?select=*,clientinfo(),contact()&clientinfo.other=like.*Main*&contact.name=like.*Tabby*&or=(clientinfo.not.is.null,contact.not.is.null) |
Hi there. Just wanted to check if there is any support for this in the works or any available workarounds to chain multiple |
@thomasdohyunkim AFAIK this is already implemented on a pre-release, but there's an issue with the clarity of the queries as Steve mentioned above. Here's an example on how to use it. The latest pre-release has this feature available. |
Hello, i need to do almost the same thing, i.e : i want to do :
you would tell me to use this sentence i suppose : but sometime i need to do :
Here i'm stuck because i don't see how to use @steve-chavez workarround with multiple field of table2 + one field of table A Do you have an idea ? |
@Etwenn Yes, and if you need to exclude the null embeddings (top level filtering), add
In this case, the filter needs to be in a separate query parameter and after that include the
NOTE: The above query is related to the issue #2800 that you opened. If the row has a column with a null value, then it won't be included in the response (when it should). But I don't see a workaround for this case. |
FYI, or conditions across embedded resources have been possible for a while now with https://postgrest.org/en/latest/references/api/resource_embedding.html#or-filtering-across-embedded-resources. Though we can still improve the syntax to be more straightforward |
Any updates here? I need to do a similar thing as @Etwenn, and the workaround proposed by @laurenceisla is driving me crazy. This is super non-intuitive for Supabase SDK users, and can be fixed only by guessing/googling. I need to basically do a chain of
|
Do you mean that if
order=clients.name,name,clients.rank
were used, then we should also consider to supportor=(clients.name.like.Chris*,and(name.eq.TopProject,clients.rank.gt.1)
?It is indeed hard to read, and
or=(clients(name).like.Chris*,and(name.eq.TopProject,clients(rank).gt.1)
seems slightly better.Originally posted by @Iced-Sun in #1414 (comment)
Also previously discussed on #2014
The text was updated successfully, but these errors were encountered: