📄 SKILL.md

← Vault

name: supabase-cli-linked-query

description: Run SQL queries against Supabase Cloud using CLI --linked flag. Config saves to CWD, not a fixed path.


Supabase CLI — linked project queries

Use when: you need to run SQL against a Supabase Cloud project using the CLI (not local).

Key discovery

supabase db query --linked does NOT use --project-ref flag. Instead it reads the linked project from a local config file.

The config is saved to ./.supabase/config.toml in the current working directory at the time you run supabase link. It is NOT saved to /tmp/supabase/.

This means:

Finding existing links

`bash

find /tmp -name "config.toml" -path "/.supabase/"

Also common: /var/www//.supabase/config.toml

`

Note on schema discovery

When unsure of column names, discover first:

`sql

SELECT column_name, data_type FROM information_schema.columns

WHERE table_name = 'my_table' ORDER BY ordinal_position;

`

Alternative: Supabase Management API (faster for direct Postgres)

The Management API bypasses CLI config entirely. Use this when CLI link is inconvenient or when GET /rest/v1/ returns empty [] due to RLS.

Power query — Management API (no RLS, no anon-key filtering):

`bash

curl -s -X POST "https://api.supabase.com/v1/projects//database/query" \

-H "Authorization: Bearer " \

-H "Content-Type: application/json" \

--data-raw '{"query": "SELECT id, email, role FROM public.profiles LIMIT 20;"}'

`

Where is the Supabase Management API personal access token (starts with sbp_).

This always returns raw Postgres rows — no supabase link, no CWD, no RLS. Useful for quick ad-hoc debugging.