Natural language to SQL

Ask in your language. Keep the meaning precise.

Natural language to SQL, also called NL2SQL or English to SQL, helps people ask data questions without starting from syntax. The important step is connecting everyday terms to the right tables and calculations.

Define ‘active’
example
prompt

Count users with a login event in the 28 days before September 1, 2026.

generated SQL PostgreSQL
1SELECT COUNT(DISTINCT user_id) AS active_users2FROM events3WHERE event_name = 'login'4  AND occurred_at >= TIMESTAMP '2026-08-04 00:00:00'5  AND occurred_at < TIMESTAMP '2026-09-01 00:00:00';

Define the terms your team actually uses

‘Active customer’ might mean a login in the last 28 days, a paid subscription, or an order this quarter. A language model cannot infer your company's definition from the phrase alone. Store that definition in project Knowledge alongside the columns and tables it refers to.

Add examples of approved calculations and explain joins that are not obvious from column names. Schema descriptions and project rules provide context on each grounded request; they are not a promise that every generated query will be correct.

Turn a broad question into a reviewable request

Instead of ‘How is revenue doing?’, ask ‘Show paid invoice revenue by month for January through August 2026, in USD, excluding test accounts.’ This specifies a metric, grain, period, currency, and exclusion that can each be checked in the SQL.

When a question has material ambiguity, the query workspace can ask for clarification. Resolve the definition before running the query. In a follow-up, explicitly say which filters should stay the same and which should change.

  • Metric: count customers, sum invoice amounts, or average elapsed time?
  • Time: which timestamp, timezone, and complete or partial period?
  • Population: include cancelled orders, internal accounts, or customers with no activity?
  • Grain: one row per customer, region, month, or event?

Review meaning as well as syntax

An English to SQL converter can generate valid SQL that answers a different question. Check whether a join multiplies amounts, whether NULL values are excluded, and whether the result covers the requested population.

Analysts can inspect these choices directly. Business users can keep the question, SQL, and resulting evidence together in an answer thread for review with the person who owns the metric.

Query examples

Prompts mapped to concrete SQL.

01 / PostgreSQL

Define ‘active’

Count users with a login event in the 28 days before September 1, 2026.

Sample schema

events(user_id, event_name, occurred_at) — timestamps use the reporting timezone
SELECT COUNT(DISTINCT user_id) AS active_users
FROM events
WHERE event_name = 'login'
  AND occurred_at >= TIMESTAMP '2026-08-04 00:00:00'
  AND occurred_at < TIMESTAMP '2026-09-01 00:00:00';

DISTINCT counts people rather than login events. The explicit boundary fixes the meaning of the 28-day window; establish the reporting timezone before applying it to your data.

Answers before you connect a database.

Is natural language to SQL the same as text to SQL?

Yes. NL2SQL, natural language to SQL, and text to SQL describe translating a language request into SQL. English to SQL is a common name for English-language requests.

Can TTSQL learn our business terminology?

Add definitions, schema descriptions, business rules, and reviewed examples to project Knowledge. Manually approved executed question/SQL pairs can also be promoted from answer threads.

Bring your next question to TTSQL.

Start with one PostgreSQL project and 20 free requests a day. Explore your data, build a report, or integrate the API.