Files
supabase/apps/reference/_supabase_js/generated/delete.mdx
T
Bobbie Soedirgo a7a56eb800 docs(reference/v2/postgrest-js): update spec
* `curl -sS https://supabase.github.io/postgrest-js/spec.json >
spec/enrichments/tsdoc_v2/postgrest.json`
* `cd spec && make transform generate.js.v2 format`
2022-09-20 16:34:12 +08:00

167 lines
3.7 KiB
Plaintext

---
id: delete
title: 'Delete data: delete()'
slug: /delete
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'
Perform a DELETE on the table or view.
By default, deleted rows are not returned. To return it, chain the call
with `.select()` after filters.
```js
const { data, error } = await supabase
.from('cities')
.delete()
.match({ id: 666 })
```
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
options
</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">
Named parameters
</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">
count
</span>
<span className="method-list-item-label-badge false">
optional
</span>
<span className="method-list-item-validation">
<code>exact</code> | <code>planned</code> | <code>estimated</code>
</span>
</h4>
<div class="method-list-item-description">
Count algorithm to use to count deleted rows.
`"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
hood.
`"planned"`: Approximated but fast count algorithm. Uses the Postgres
statistics under the hood.
`"estimated"`: Uses exact count for low numbers and planned count for high
numbers.
</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">
estimated
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
literal
</span>
</h4>
<div class="method-list-item-description">
No description provided.
</div>
</li>
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
planned
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
literal
</span>
</h4>
<div class="method-list-item-description">
No description provided.
</div>
</li>
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
exact
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
literal
</span>
</h4>
<div class="method-list-item-description">
No description provided.
</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
## Notes
- `delete()` should always be combined with [filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
- If you use `delete()` with filters and you have
[RLS](/docs/learn/auth-deep-dive/auth-row-level-security) enabled, only
rows visible through `SELECT` policies are deleted. Note that by default
no rows are visible, so you need at least one `SELECT`/`ALL` policy that
makes the rows visible.
## Examples
### Delete records
```js
const { data, error } = await supabase
.from('cities')
.delete()
.match({ id: 666 })
```