mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 05:44:25 +08:00
104 lines
2.4 KiB
Plaintext
104 lines
2.4 KiB
Plaintext
---
|
|
id: or
|
|
title: '.or()'
|
|
slug: /or
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs'
|
|
import TabItem from '@theme/TabItem'
|
|
|
|
Finds all rows satisfying at least one of the filters.
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.or('id.eq.20,id.eq.30')
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
filters
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The filters to use, separated by commas.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
foreignTable
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The foreign table to use (if `column` is a foreign column).
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
## Notes
|
|
|
|
- `.or()` expects you to use the raw [PostgREST syntax](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for the filter names and values.
|
|
|
|
```js
|
|
.or('id.in.(6,7), arraycol.cs.{"a","b"}') // Use Postgres list () for in filter. Array {} for array column and 'cs' for contains.
|
|
.or(`id.in.(${arrList}),arraycol.cs.{${arr}}`) // You can insert a javascipt array for list or array on array column.
|
|
.or(`id.in.(${arrList}),rangecol.cs.[${arrRange})`) // You can insert a javascipt array for list or range on a range column.
|
|
```
|
|
|
|
## Examples
|
|
|
|
### With `select()`
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.or('id.eq.20,id.eq.30')
|
|
```
|
|
|
|
### Use `or` with `and`
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.select('name, country_id')
|
|
.or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
|
|
```
|
|
|
|
### Use `or` on foreign tables
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('countries')
|
|
.select('id, cities(*)')
|
|
.or('name.eq.Wellington,name.eq.Paris', { foreignTable: 'cities' })
|
|
```
|