mirror of
https://github.com/supabase/supabase.git
synced 2026-05-24 04:00:47 +08:00
195 lines
3.8 KiB
Plaintext
195 lines
3.8 KiB
Plaintext
---
|
|
id: update
|
|
title: "Modify data: update()"
|
|
slug: update
|
|
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabsPanel from '@theme/TabsPanel';
|
|
|
|
Performs an UPDATE on the table.
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Middle Earth' })
|
|
.match({ name: 'Auckland' })
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</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">
|
|
values
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>Partial</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The values to update.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
__namedParameters
|
|
</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">
|
|
|
|
No description provided.
|
|
|
|
</div>
|
|
|
|
<ul className="method-list-group">
|
|
<h5 class="method-list-title method-list-title-isChild expanded">Properties</h5>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
returning
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>minimal</code> | <code>representation</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
By default the updated record is returned. Set this to 'minimal' if you don't need this value.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
count
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>null</code> | <code>exact</code> | <code>planned</code> | <code>estimated</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
Count algorithm to use to count rows in a table.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
## Notes
|
|
|
|
- `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
### Updating your data
|
|
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('cities')
|
|
.update({ name: 'Middle Earth' })
|
|
.match({ name: 'Auckland' })
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
### Updating JSON data
|
|
|
|
Postgres offers a
|
|
[number of operators](https://www.postgresql.org/docs/current/functions-json.html)
|
|
for working with JSON data. Right now it is only possible to update an entire JSON document,
|
|
but we are [working on ideas](https://github.com/PostgREST/postgrest/issues/465) for updating individual keys.
|
|
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="reference/supabase-js"
|
|
values={[{ label: 'JavaScript', value: 'js' }]}>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { data, error } = await supabase
|
|
.from('users')
|
|
.update(`
|
|
address: {
|
|
street: 'Melrose Place',
|
|
postcode: 90210
|
|
}
|
|
`)
|
|
.eq('address->postcode', 90210)
|
|
```
|
|
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs> |