Updating

Toggle Example Tables

We will be fictional "world" database in all of our examples.

Countries
idnameiso2continent
76BrazilBRSouth America
156ChinaCNAsia
250FranceFREurope
554New ZealandNZOceania
566NigeriaNGAfrica
840United StatesUSNorth America
Cities
namecountry_id
Rio de Janeiro76
Beijing156
Paris250
Auckland554
Lagos556
San Francisco840

Update record

Updates information about a city.
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', '1a2b-3c4d-5e6f-7g8h')
const updateCityName = async () => {
try {
let updates = await supabase
.from('cities')
.update({ name: 'Middle Earth' })
.match({ name: 'Auckland' })
return updates
} catch (error) {
console.log('Error: ', error)
}
}

Reference

from()

supabase
.from(tableName)

tableName: string

Name of the database table to be listened to. Using the wildcard "*" will lead to all tables to be listened to.

tableName: string

Name of the database table that will be read from.

tableName: string

Name of the database table where data will be saved.

tableName: string

Name of the database table where data will be updated.

tableName: string

Name of the database table where data will be deleted.


update()

supabase
.from(tableName)
.update(data, options?)

data: object

New record values.

options: object?

const options = {
bulk: false // Protects against bulk updates. Set to true if you intend to perform a bulk change.
}

Filtering

filter()

Shows how to use filter( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.filter('name', 'eq', 'Paris')
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.filter(columnName, operator, criteria)

This allows you to apply various filters on your query. Filters can also be chained together.

columnName: string

Name of the database column.

operator: string

Name of filter operator to be utilised.

criteria: { object | array | string | integer | boolean | null }

Value to compare to. Exact data type of criteria would depend on the operator used.


match()

Shows how to use match( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.match({name: 'Beijing', country_id: 156})
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.match(filterObject)

Finds rows that exactly match the specified filterObject. Equivalent of multiple filter('columnName', 'eq', criteria).

filterObject: object

An object of { 'columnName': 'criteria' }


eq()

Shows how to use eq( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.eq('name', 'San Francisco')
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.eq(columnName, filterValue)

Finds all rows whose value on the stated columnName exactly matches the specified filterValue. Equivalent of filter(columName, 'eq', criteria).

columnName: string

Name of the database column.

filterValue: { string | integer | boolean }

Value to match.


gt()

Shows how to use gt( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.gt('country_id', 250)
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.gt(columnName, filterValue)

Finds all rows whose value on the stated columnName is greater than the specified filterValue. Eqiuvalent of filter(columnName, 'gt', criteria).

columnName: string

Name of database column.

filterValue: { string | integer | boolean }

Value to compare to.


lt()

Shows how to use lt( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.lt('country_id', 250)
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.lt(columnName, filterValue)

Finds all rows whose value on the stated columnName is less than the specified filterValue. Eqiuvalent of filter(columnName, 'lt', criteria).

columnName: string

Name of database column.

filterValue: { string | integer | boolean }

Value to compare to.


gte()

Shows how to use gte( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.gte('country_id', 250)
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.gte(columnName, filterValue)

Finds all rows whose value on the stated columnName is greater than or equal to the specified filterValue. Eqiuvalent of filter(columnName, 'gte', criteria).

columnName: string

Name of database column.

filterValue: { string | integer | boolean }

Value to compare to.


lte()

Shows how to use lte( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.lte('country_id', 250)
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.lte(columnName, filterValue)

Finds all rows whose value on the stated columnName is less than or equal to the specified filterValue. Eqiuvalent of filter(columnName, 'lte', criteria).

columnName: string

Name of database column.

filterValue: { string | integer | boolean }

Value to compare to.


like()

Shows how to use like( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.like('name', '%la%')
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.like(columnName, stringPattern)

Finds all rows whose value in the stated columnName matches the supplied pattern. Equivalent of filter(columnName, 'like', stringPattern).

columnName: string

Name of database column.

stringPattern: string

String pattern to compare to. A comprehensive guide on how to form proper patterns can be found here.


ilike()

Shows how to use ilike( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.ilike('name', '%la%')
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.ilike(columnName, stringPattern)

A case-sensitive version of like(). Equivalent of filter(columnName, 'ilike', stringPattern).

columnName: string

Name of database column.

stringPattern: string

String pattern to compare to. A comprehensive guide on how to form proper patterns can be found here.


is()

Shows how to use is( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.is('name', null)
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.is(columnName, filterValue)

A check for exact equality (null, true, false), finds all rows whose value on the state columnName exactly match the specified filterValue. Equivalent of filter(columnName, 'is', filterValue).

columnName: string

Name of database column.

filterValue: { null | boolean }

Value to match.


in()

Shows how to use in( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.in('name', ['Rio de Janeiro', 'San Francisco'])
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.in(columnName, filterArray)

Finds all rows whose value on the stated columnName is found on the specified filterArray. Equivalent of filter(columnName, 'in', criteria).

columnName: string

Name of database column.

filterArray: array

Array of values to find a match. Data type of values is dependent on the columnName specified.


not()

Shows how to use not( ) with update( )
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('https://world.supabase.co', 'public-key-bOYapLADERfE')
const updateCityName = async () => {
try {
let cities = await supabase
.from('cities')
.not('name', 'Lagos')
.update({ name: 'Mordor' })
return cities
} catch (error) {
console.log('Error: ', error)
}
}

General form

supabase
.from(tableName)
.not(columnName, filterValue)

Finds all rows whose value on the stated columnName does not match the specified filterValue. Equivalent of filter(columnName, 'not', criteria).

columnName: string

Name of database column.

filterValue: { string | integer | boolean }

Value to not match.


Responses

200 OK

Successful request

400 Bad request

An invalid syntax or configuration was sent.

401 Unauthorized

Invalid credentials were provided.

404 Not found

Requested resource cannot be found.

406 Not acceptable

The response provided by the server does not match the list of acceptable values stated in the request's headers.

500 Internal Server Error

The server was unable to encounter the situation it encountered.