Database Functions & Triggers in Supabase

From the Supabase cheat sheet ยท Advanced Features ยท verified Jul 2026

Database Functions & Triggers

Custom functions and automatic triggers

sql
-- Create function
CREATE FUNCTION increment_views(post_id INT)
RETURNS void AS $$
BEGIN
  UPDATE posts
  SET views = views + 1
  WHERE id = post_id;
END;
$$ LANGUAGE plpgsql;

-- Call from client
const { data, error } = await supabase
  .rpc('increment_views', { post_id: 123 })
๐Ÿ”ง Custom business logic in database
โšก Triggers for automatic actions
๐Ÿ” Secure with SECURITY DEFINER
๐Ÿ“Š Complex queries and transactions

More Supabase tasks

Back to the full Supabase cheat sheet