Natural language to SQL inside Google Sheets
You shouldn't need to remember JOIN syntax to ask your database for the top 10 customers by total order amount. You shouldn't need to think about PartiQL constraints to query DynamoDB. You shouldn't need to memorize PostgREST's filter syntax to slice a Supabase table.
gptsheet's Ask SQL feature does the translation. Type the question in plain English; the formula generates the right query for your DB; you click Run; the rows land in the sheet.
How it works
- You connect a DB connector — MySQL, MS SQL, Postgres, Supabase, or DynamoDB — via the sidebar (browser → DB, no proxy).
- Expand the connector card. Below "Browse tables" you see Ask.
- Type a question: "top 10 customers by total order amount in the last 30 days".
- Hit Generate. gptsheet fetches the live schema (tables + columns) and sends it to your LLM provider along with the question.
- The generated SQL appears in an editable code box. Review it.
- Hit Run. The query executes; rows write into the active cell; the query is saved as an Import you can rerun later.
Per-database behavior
| Database | Generates | Schema fetched from |
|---|---|---|
| MySQL | MySQL SELECT | INFORMATION_SCHEMA.COLUMNS |
| MS SQL Server | T-SQL SELECT (TOP 1000) | INFORMATION_SCHEMA.COLUMNS |
| Postgres (PostgREST) | PostgREST URL fragment | OpenAPI / spec |
| Supabase | PostgREST URL fragment | OpenAPI / spec |
| DynamoDB | PartiQL SELECT | ListTables + DescribeTable |
Each database has its own dialect quirks; the system prompt is tuned per-database to respect them (no JOINs in PartiQL, no SQL JOINs in PostgREST — use embedded resources, etc.).
Example: Postgres / Supabase
Schema: customers (id, email, plan, created_at), orders (id, customer_id, total, created_at).
Question: "top 10 customers by total order amount this month".
Generated PostgREST URL:
customers?select=email,plan,orders(total)&orders.created_at=gte.2026-05-01&order=orders.total.desc&limit=10
No JOIN keyword. PostgREST uses embedded resources for joins. The LLM knows this — gptsheet's prompt teaches it.
Example: DynamoDB
Tables: Orders (OrderId [HASH], CreatedAt [RANGE]), Users (UserId [HASH]).
Question: "orders for OrderId 'O-12345'".
Generated PartiQL:
SELECT * FROM "Orders" WHERE OrderId = 'O-12345'
PartiQL constraints respected: no JOINs, no GROUP BY, partition-key filter for indexed access. The schema fetch includes [HASH] / [RANGE] hints so the LLM picks efficient filters.
Safety
Generated SQL is shown before running. You can edit it. If the generated statement contains INSERT / UPDATE / DELETE / DROP / ALTER / TRUNCATE / CREATE / GRANT / REVOKE, a confirmation prompt asks you to approve. The system prompt explicitly forbids these, but the confirmation is a second line of defense.
Saved as Imports
Every Ask SQL run is saved as an Import you can rerun. Useful patterns:
- Generate once, schedule daily refresh. "Top 10 customers this month" becomes a live tile.
- Generate once, edit the SQL slightly, rerun. The LLM is a starting point; you tune from there.
- Share the sheet — the Import + spec is bound to the sheet, so a teammate refreshing inherits the same query against their own DB credentials.
When this isn't enough
- Very large schemas (1,000+ tables). The schema dump approaches LLM context limits. Workaround: hide irrelevant tables in your DB first, or write the query manually.
- Vendor-specific functions. Postgres'
jsonb_array_elements, MySQL'sJSON_TABLE, etc. — the LLM is hit-or-miss on niche functions. Review carefully. - Performance-tuned queries. The LLM optimizes for correctness, not query plans. For high-frequency scheduled imports, hand-tune the final SQL.
Cost
Each generation call: ~1,500 input tokens (schema + question) + ~150 output tokens (SQL). At Gemini Flash list prices: ~$0.0001 per query. Effectively free.
The cost you actually care about is the SQL execution against your own DB — that's free if you self-host, or normal Stripe/Heroku/RDS pricing if you don't.
Try Ask SQL on your DB
DB connectors are in the Max tier — $299 lifetime. Includes 5 databases + the SQL Builder.
Get gptsheet Max