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