Database
RDS Supabase is built on ApsaraDB RDS for PostgreSQL and offers standard PostgreSQL capabilities. It automatically generates Data APIs, including RESTful APIs, so you can perform create, read, update, and delete (CRUD) operations on your data immediately.
All examples use the Supabase JavaScript client library and follow the supabase.from('<table>').method() chaining pattern.
Basic operations
Retrieve data
select() performs a SELECT query on a table or view.
const { data, error } = await supabase
.from('characters')
.select()
Insert data
insert() adds one or more rows to a table. By default, inserted rows are not returned. To return the inserted rows, chain .select() after the call.
const { error } = await supabase
.from('countries')
.insert({ id: 1, name: 'Mordor' })
Update data
update() modifies existing rows in a table. By default, updated rows are not returned. To return the updated rows, chain .select() after the filter.
const { error } = await supabase
.from('instruments')
.update({ name: 'piano' })
.eq('id', 1)
Upsert data
upsert() inserts a row if no conflict is found, or updates the existing row if one is found. Use the onConflict parameter to specify one or more columns to check for conflicts.
By default, upserted rows are not returned. To return the rows, chain .select() after the call.
// Insert or update based on primary key
const { data, error } = await supabase
.from('instruments')
.upsert({ id: 1, name: 'piano' })
.select()
// Insert or update based on a specific column
const { data, error } = await supabase
.from('users')
.upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' }, { onConflict: 'handle' })
.select()
Delete data
delete() removes rows from a table that match the specified filter. By default, deleted rows are not returned. To return the deleted rows, chain .select() after the filter.
const response = await supabase
.from('countries')
.delete()
.eq('id', 1)
Configure custom PostgREST parameters
Use the postgres user to run the following SQL statements in the SQL Editor of the Supabase console (Supabase Dashboard) to configure custom PostgREST parameters, such as the schemas exposed by the Data API and the maximum number of rows returned per request.
-- Check whether the required SET privileges are granted
SELECT
has_parameter_privilege('postgres', 'pgrst.db_schemas', 'SET') AS can_set_schemas,
has_parameter_privilege('postgres', 'pgrst.db_max_rows', 'SET') AS can_set_max_rows;
-- Database schemas exposed by PostgREST (visible scope of API routes)
ALTER ROLE authenticator SET pgrst.db_schemas = 'public,storage,graphql_public,finance';
-- Maximum number of rows that PostgREST fetches per request (hard limit)
ALTER ROLE authenticator SET pgrst.db_max_rows = '2';
-- Notify PostgREST to reload the configuration (required for the changes to take effect)
NOTIFY pgrst, 'reload config';
NOTIFY pgrst, 'reload schema';
-- View the configuration result
SELECT rolname, rolconfig
FROM pg_roles
WHERE rolname = 'authenticator';
References
-
To learn more about Supabase database features, see Database.
-
For the full Supabase JavaScript client library reference, see JavaScript.
-
To learn about the REST API for managing databases, see Postgres REST API.