Files
supabase/web/docs/client/select.mdx
T
ykdojo 0ae83a337e Test generating docs
I tried running npm run gen:supabase, and this is the result.
2020-12-22 12:48:50 -08:00

254 lines
3.9 KiB
Plaintext

---
id: select
title: "Fetch data: select()"
slug: select
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
Performs horizontal filtering with SELECT.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('cities')
.select()
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
columns
</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 columns to retrieve, separated by commas.
</div>
</li>
</ul>
## Notes
- `select()` can be combined with [Modifiers](/docs/client/using-modifiers)
- `select()` can be combined with [Filters](/docs/client/using-filters)
## Examples
### Getting your data
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('cities')
.select()
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### Selecting specific columns
You can select specific fields from your tables.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('cities')
.select('name')
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### Query foreign tables
If your database has relationships, you can query related tables too.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('countries')
.select(`
name,
cities (
name
)
`)
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### Query the same foreign table multiple times
Sometimes you will need to query the same foreign table twice.
In this case, you can use the name of the joined column to identify
which join you intend to use. For convenience, you can also give an
alias for each column. For example, if we had a shop of products,
and we wanted to get the supplier and the purchaser at the same time
(both in the users) table:
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('products')
.select(`
id,
supplier:supplier_id ( name ),
purchaser:purchaser_id ( name )
`)
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>
### Quering JSON data
If you have data inside of a JSONB column, you can apply select
and query filters to the data values. Postgres offers a
[number of operators](https://www.postgresql.org/docs/9.5/functions-json.html)
for querying JSON data. Also see
[PostgREST docs](http://postgrest.org/en/v7.0.0/api.html#json-columns) for more details.
<Tabs
defaultValue="js"
groupId="libraries"
values={[{ label: 'JavaScript', value: 'js' },{ label: 'Python', value: 'py' }]}>
<TabItem value="js">
```js
const { data, error } = await supabase
.from('products')
.select(`
id,
supplier:supplier_id ( name ),
purchaser:purchaser_id ( name )
`)
```
</TabItem>
<TabItem value="py">
```py
# Not yet implemented
```
</TabItem>
</Tabs>