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:

  1. Go to supabase.com
  2. Click "Start your project"
  3. 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

  1. From the Dashboard, click "New Project"
  2. Enter a project name
  3. Set a database password
  4. Choose a region
  5. Click "Create new project"

Wait for setup to complete (about 2 minutes).

3

Create the SQL Function

  1. Go to SQL Editor in your Supabase Dashboard
  2. Click "New query"
  3. 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

  1. Go to Project Settings → API
  2. Copy your Project URL (https://xxxxx.supabase.co)
  3. Copy the anon/public key
⚠️

Only use the anon/public key, NOT the service_role key.

5

Connect & Start Querying

  1. Go to the Playground
  2. Paste your Project URL and anon key
  3. Click "Connect to Supabase"
  4. 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.