最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

curl - PostgREST API - mutiple OR conditions. Is it possible? - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a query using PostgREST API with multiple OR conditions.

Essentially I need PostgREST query similar to this SQL query

SELECT * FROM people
WHERE condition1 AND (condition2 OR condition3) AND (condition4 OR condition5)

I found multiple solution/examples for one OR condition. For example:

GET /people?grade=gte.90&or=(age.eq.14,and(age.gte.21,age.lte.27))

Above example translates to:

SELECT * FROM people WHERE grade>=90 AND (age=14 OR (age>=21 AND age <=27))

How to add more than one?

Any help is appreciated.

I'm trying to create a query using PostgREST API with multiple OR conditions.

Essentially I need PostgREST query similar to this SQL query

SELECT * FROM people
WHERE condition1 AND (condition2 OR condition3) AND (condition4 OR condition5)

I found multiple solution/examples for one OR condition. For example:

GET /people?grade=gte.90&or=(age.eq.14,and(age.gte.21,age.lte.27))

Above example translates to:

SELECT * FROM people WHERE grade>=90 AND (age=14 OR (age>=21 AND age <=27))

How to add more than one?

Any help is appreciated.

Share Improve this question asked Feb 4 at 18:26 Miloš ĐorđevićMiloš Đorđević 1
Add a comment  | 

1 Answer 1

Reset to default 0

Every filter in a query parameter is separated with an AND by default when translating to SQL. For example:

GET /people?first_name=eq.Peter&last_name=eq.Smith&age=eq.30

Is equivalent in SQL to:

SELECT *
FROM people
WHERE first_name = 'Peter' AND last_name = 'Smith' AND age = 30

So, to get the query you want, you need to specify each or=(...) filter in their respective query parameter:

GET /people?<condition1>&or=(<condition2>,<condition3>)&or=(<condition4>,<condition5>)

As a side note, using and=(...) is more useful when you have to nest inside an or=(...) for example, since the query parameters won't work there.

发布评论

评论列表(0)

  1. 暂无评论