Supabase Setup Guide
Follow these steps to connect your database. It only takes a few minutes.
1
Create a Supabase Account
Sign up for a free Supabase account:
- Go to supabase.com
- Click "Start your project"
- Sign up with GitHub, Google, or email
The free tier includes 500MB database, 1GB file storage, and 50,000 MAU.
2
Create a New Project
- From the Dashboard, click "New Project"
- Enter a project name
- Set a database password
- Choose a region
- Click "Create new project"
Wait for setup to complete (about 2 minutes).
3
Create the SQL Function
- Go to SQL Editor in your Supabase Dashboard
- Click "New query"
- Paste the SQL below and click "Run"
exec_sql function
CREATE OR REPLACE FUNCTION exec_sql(query_text TEXT)
RETURNS JSON
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
result JSON;
is_select BOOLEAN;
BEGIN
is_select := UPPER(LTRIM(query_text)) ~ '^(SELECT|WITH|TABLE|VALUES|SHOW|EXPLAIN)';
IF is_select THEN
EXECUTE 'SELECT COALESCE(json_agg(row_to_json(t)), ''[]''::json) FROM ('
|| query_text || ') t'
INTO result;
RETURN result;
ELSE
EXECUTE query_text;
RETURN json_build_object(
'status', 'success',
'message', 'Query executed successfully'
);
END IF;
EXCEPTION WHEN OTHERS THEN
RAISE EXCEPTION '%', SQLERRM;
END;
$$;You should see "Success. No rows returned"
4
Get Your API Credentials
- Go to Project Settings → API
- Copy your Project URL (
https://xxxxx.supabase.co) - Copy the anon/public key
⚠️
Only use the anon/public key, NOT the service_role key.
5
Connect & Start Querying
- Go to the Playground
- Paste your Project URL and anon key
- Click "Connect to Supabase"
- Start writing SQL!
-- Quick test:
CREATE TABLE test (id SERIAL PRIMARY KEY, msg TEXT);
INSERT INTO test (msg) VALUES ('Hello from QSQL!');
SELECT * FROM test;Troubleshooting
Connection failed
Double-check your Project URL (must include https://) and anon key. Make sure your project is not paused.
"function exec_sql does not exist"
Go back to Step 3 and run the SQL in your Supabase SQL Editor.
Permission denied
Make sure the function uses SECURITY DEFINER. Add RLS policies if needed.
Empty results
Ensure the table has data. Run an INSERT first, then SELECT.