Extend your database with powerful PostgreSQL extensions
PostgreSQL extensions add functionality beyond the core database capabilities. Supabase comes pre-configured with over 50 extensions, including popular ones for vector search, full-text search, geospatial data, and more.
-- Enable an extensioncreate extension if not exists pgvector with schema extensions;-- Enable with specific schemacreate extension if not exists postgis with schema public;
-- View all installed extensionsselect extname as extension_name, extversion as version, nspname as schemafrom pg_extensionjoin pg_namespace on pg_extension.extnamespace = pg_namespace.oidorder by extname;
Store and query vector embeddings for AI/ML applications.
-- Enable the extensioncreate extension if not exists vector;-- Create a table with vector columncreate table documents ( id bigint primary key generated always as identity, content text, embedding vector(1536) -- OpenAI embeddings are 1536 dimensions);-- Create an index for fast similarity searchcreate index on documents using ivfflat (embedding vector_cosine_ops) with (lists = 100);-- Find similar documentsselect id, contentfrom documentsorder by embedding <=> '[0.1, 0.2, ...]'::vectorlimit 5;
-- Enable pg_netcreate extension if not exists pg_net;-- Make a simple GET requestselect net.http_get( url := 'https://api.github.com/repos/supabase/supabase', headers := '{"User-Agent": "supabase"}' ) as response;-- Make a POST requestselect net.http_post( url := 'https://api.example.com/webhook', headers := '{"Content-Type": "application/json"}', body := jsonb_build_object( 'event', 'user.created', 'user_id', 123 ) );-- Use in a trigger to call webhookscreate or replace function notify_webhook()returns trigger as $$begin perform net.http_post( url := 'https://api.example.com/webhook', headers := '{"Content-Type": "application/json"}', body := row_to_json(new) ); return new;end;$$ language plpgsql;
-- Enable extensioncreate extension if not exists pg_trgm;-- Create index for fast similarity searchcreate index on products using gin (name gin_trgm_ops);-- Find similar productsselect name, similarity(name, 'iPhone') as simfrom productswhere name % 'iPhone' -- % operator for similarityorder by sim desclimit 5;-- Fuzzy searchselect *from userswhere username ilike '%john%'order by similarity(username, 'john') desc;
Most extensions are installed in the extensions schema to keep things organized:
-- Install in extensions schema (recommended)create extension pgvector with schema extensions;-- Use fully qualified namesselect extensions.vector_dims('[1,2,3]'::extensions.vector);-- Or set search pathset search_path to public, extensions;select vector_dims('[1,2,3]'::vector);
The extensions schema is accessible to public by default. For sensitive extensions, create a separate schema with restricted access.
-- Check current versionselect extversion from pg_extension where extname = 'pgvector';-- Upgrade extensionalter extension pgvector update to '0.5.0';-- Upgrade to latest versionalter extension pgvector update;
-- Example: Install a custom extension from SQLcreate schema if not exists my_extensions;create or replace function my_extensions.custom_function()returns textlanguage sqlas $$ select 'Hello from custom extension!';$$;
For more complex extensions, use the database.dev package manager or submit an extension request.