Flutter/Supabase - problem with multiple OR in filters

292 Views Asked by At

I am using Supabase as my Flutter app backend, and I've hit a problem trying to build a complex SQL query using the Flutter

Here is the query I am trying to create in SQL...

select 
"instanceId","scheduled"->>'absolute',"taskOpen" from gd_task
where 
("scheduled"->>'absolute' >= '2023-07-19' and "scheduled"->>'absolute' <= '2023-07-25')
or
("scheduled"->>'absolute' < '2023-07-19' AND "taskOpen" = true)
or
("scheduled"->>'absolute' < '2023-07-19'  AND "taskOpen" = false AND "actualFinish" = '2023-07-19')

Building the same thing in the Flutter Supabase query classes, I end up with the following three 'or' filter being added to the query...

.or('scheduled->>absolute.gte.2023-07-19T00:00:00.000,and(scheduled->>absolute.lte.2023-07-25T23:59:59.000)')
.or('scheduled->>absolute.lt.2023-07-19T00:00:00.000,and(taskOpen.eq.true)')
.or('scheduled->>absolute.lt.2023-07-19T00:00:00.000,and(taskOpen.eq.false),and(actualFinish.eq.2023-07-19T00:00:00.000)')

... but this is not returning the correct results

In particular, the data from the 1st 'or' is not being returned

Drilling into the Supabase Flutter code, the URI ends up as...

https://muordrkfvnxbdpnlesix.supabase.co/rest/v1/gd_task?select=%2A&or=%28scheduled-%3E%3Eabsolute.gte.2023-07-19T00%3A00%3A00.000%2Cand%28scheduled-%3E%3Eabsolute.lte.2023-07-20T00%3A00%3A00.000%29%29&or=%28scheduled-%3E%3Eabsolute.lt.2023-07-19T00%3A00%3A00.000%2Cand%28taskOpen.eq.true%29%29&or=%28scheduled-%3E%3Eabsolute.lt.2023-07-19T00%3A00%3A00.000%2Cand%28taskOpen.eq.false%29%2Cand%28actualFinish.eq.2023-07-19T00%3A00%3A00.000%29%29

Any suggestions?

1

There are 1 best solutions below

0
On

Resolved. I had misread the Supabase/Flutter guide on how the 'or' function works, and this only became apparent once I'd read the Pgx rest api guide