Template for adding a constraint.
Update a column timestamp on every update.
Set of functions to perform calculation on a set of values. The return is a single summary value. (Except for "round()")
Schedule PostgreSQL commands directly from the database.
Template to modify a column type. Make sure to change the name and type.
Basic view template. Change according to your preference.
Basic table template. Change "table_name" to the name you prefer.
Template to create a simple function.
Template to create a function that return integer like count of rows.
Template to create a function a function that return set of table.
Table with constraints example.
Table with foreign key (fk) template. Change "table_name" to the name you prefer.
Delete items in Storage using SQL
Template for dropping / removing constraint.
Template for dropping / removing function.
Template for dropping / removing row level security.
Template for dropping / removing trigger from table.
How to use full text search in PostgreSQL.
Generate YouTube-like short IDs as Postgres Primary Keys.
Insert new user data into another table when event new user signup using Supabase Auth.
Update a field with incrementing value using stored procedure.
Javascript snippets.
List all constraints and their tables.
List all foreign keys (FKs) and their columns.
List all the functions in (predefined/user-defined).
List all primary keys (PKs) and their columns.
List all table data size.
List all the triggers in (predefined/user-defined).
Row level security with advanced/complicated policies.
Row level security that requires table joins .
Row level security that make use of security definer functions .
Row level security for read access.
Row level security for restrict updates.
Row level security policies to implement TTL.
Row level security that verify email domains.
Template to rename any constraints you have.
Define a sequence generator.
Check your database version.
Starter template for the Next.js Stripe Subscriptions Starter.
Build a todo list with Row Level Security.
Template for updating a constraint.
List all foreign keys (FKs) and their columns.
select kcu.table_schema || '.' || kcu.table_name as foreign_table,
'>-' as rel,
rel_kcu.table_schema || '.' || rel_kcu.table_name as primary_table,
kcu.ordinal_position as no,
kcu.column_name as fk_column,
'=' as join,
rel_kcu.column_name as pk_column,
kcu.constraint_name
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu
on tco.constraint_schema = kcu.constraint_schema
and tco.constraint_name = kcu.constraint_name
join information_schema.referential_constraints rco
on tco.constraint_schema = rco.constraint_schema
and tco.constraint_name = rco.constraint_name
join information_schema.key_column_usage rel_kcu
on rco.unique_constraint_schema = rel_kcu.constraint_schema
and rco.unique_constraint_name = rel_kcu.constraint_name
and kcu.ordinal_position = rel_kcu.ordinal_position
where tco.constraint_type = 'FOREIGN KEY'
order by kcu.table_schema,
kcu.table_name,
kcu.ordinal_position;