You need to agree to share your contact information to access this dataset

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this dataset content.

DocBench: A Synthetic DuckDB Text-to-SQL Benchmark

DocBench is a synthetic Text-to-SQL benchmark dataset consisting of 2430 question/sql pairs derived from the DuckDB documentation, specifically designed to probe language models for knowledge of DuckDB-specific SQL functionality. The dataset covers functions, aggregates, operators, statements, keywords, and multi-keyword expressions available in DuckDB 1.1.3 and its default extensions.

Dataset Structure

Each example contains:

  • category: Difficulty level (easy, medium, hard)
  • question: Natural language question/instruction
  • sql: Ground truth SQL query
  • setup_sql: SQL to create necessary schema/data
  • validation_sql: SQL to validate query results
  • type: Type of SQL construct being tested
  • name: Name of the specific function/feature
  • docs_oracle: Relevant documentation for the construct

Files

  • duckdb-synth.jsonl: The benchmark dataset (2430 examples)
  • duckdb-distilled-docs.jsonl: Distilled documentation for each construct (870 entries)

Prompt Templates

Benchmark Generation Prompt

The following prompt template was used to generate the synthetic Text-to-SQL benchmark for testing language models on DuckDB-specific syntax. The dataset was created using DeepSeek-V3 (DeepSeek license applies).

Here are some DuckDB SQL syntax specifics you should be aware of:
- DuckDB uses double quotes (") for identifiers that contain spaces or special characters, or to force case-sensitivity and single quotes (') to define string literals
- DuckDB can query CSV, Parquet, and JSON directly without loading them first, e.g. `SELECT * FROM 'data.csv';`
- DuckDB supports CREATE TABLE AS: `CREATE TABLE new_table AS SELECT * FROM old_table;`
- DuckDB queries can start with FROM, and optionally omit SELECT *, e.g. `FROM my_table WHERE condition;` is equivalent to `SELECT * FROM my_table WHERE condition;`
- DuckDB allows you to use SELECT without a FROM clause to generate a single row of results or to work with expressions directly, e.g. `SELECT 1 + 1 AS result;`
- DuckDB supports attaching multiple databases, using the ATTACH statement: `ATTACH 'my_database.duckdb' AS mydb;`. Tables within attached databases can be accessed using the dot notation (.), e.g. `SELECT * FROM mydb.table_name syntax`. The default database doesn't require the dot notation to access tables. The default database can be changed with the USE statement, e.g. `USE my_db;`.
- DuckDB is generally more lenient with implicit type conversions (e.g. `SELECT '42' + 1;` - Implicit cast, result is 43), but you can always be explicit using `::`, e.g. `SELECT '42'::INTEGER + 1;`
- DuckDB can extract parts of strings and lists using [start:end] or [start:end:step] syntax. Indexes start at 1. String slicing: `SELECT 'DuckDB'[1:4];`. Array/List slicing: `SELECT [1, 2, 3, 4][1:3];`
- DuckDB has a powerful way to select or transform multiple columns using patterns or functions. You can select columns matching a pattern: `SELECT COLUMNS('sales_.*') FROM sales_data;` or transform multiple columns with a function: `SELECT AVG(COLUMNS('sales_.*')) FROM sales_data;`
- DuckDB has an easy way to include/exclude or modify columns when selecting all: e.g. Exclude: `SELECT * EXCLUDE (sensitive_data) FROM users;` Replace: `SELECT * REPLACE (UPPER(name) AS name) FROM users;`
- DuckDB has a shorthand for grouping/ordering by all non-aggregated/all columns. e.g `SELECT category, SUM(sales) FROM sales_data GROUP BY ALL;` and `SELECT * FROM my_table ORDER BY ALL;`
- DuckDB can combine tables by matching column names, not just their positions using UNION BY NAME. E.g. `SELECT * FROM table1 UNION BY NAME SELECT * FROM table2;`
- DuckDB has an intuitive syntax to create List/Struct/Map and Array types. List: `SELECT [1, 2, 3] AS my_list;`, Array: `SELECT [1, 2, 3]::FLOAT[3] AS my_list;`, Struct: `{{'a': 1, 'b': 'text'}} AS my_struct;`, Map: `MAP([1,2],['one','two']) as my_map;`. Array types are fixed size, while list types have variable size.
- DuckDB has an intuitive syntax to access struct fields using dot notation (.) or brackets ([]) with the field name. Map fields can be accessed by brackets ([]).
- DuckDB's way of converting between text and timestamps, and extract date parts. Current date as 'YYYY-MM-DD': `SELECT strftime(NOW(), '%Y-%m-%d');` String to timestamp: `SELECT strptime('2023-07-23', '%Y-%m-%d')::TIMESTAMP;`, Extract Year from date: `SELECT EXTRACT(YEAR FROM DATE '2023-07-23');`
- Column Aliases in WHERE/GROUP BY/HAVING: You can use column aliases defined in the SELECT clause within the WHERE, GROUP BY, and HAVING clauses. E.g.: `SELECT a + b AS total FROM my_table WHERE total > 10 GROUP BY total HAVING total < 20;`
- DuckDB allows generating lists using expressions similar to Python list comprehensions. E.g. `SELECT [x*2 FOR x IN [1, 2, 3]];` Returns [2, 4, 6].
- DuckDB allows chaining multiple function calls together using the dot (.) operator. E.g.: `SELECT 'DuckDB'.replace('Duck', 'Goose').upper(); -- Returns 'GOOSEDB';`
- DuckDB has a JSON data type. It supports selecting fields from the JSON with a JSON-Path expression using the arrow operator, -> (returns JSON) or ->> (returns text). For example: `SELECT data->'$.user.id' AS user_id, data->>'$.event_type' AS event_type FROM events;`
- DuckDB has built-in functions for regex: regexp_matches(column, regex), regexp_replace(column, regex), and regexp_extract(column, regex).
- DuckDB has a way to quickly get a subset of your data with `SELECT * FROM large_table USING SAMPLE 10%;`

You should help with creating a Text-2-SQL benchmark. You should generate a question and a corresponding SQL query that tests a language model for very specific knowledge of DuckDB SQL.

One benchmark example should consists of the following:
1. A natural language question/instruction (question)
2. The ground truth SQL query (query)
3. A SQL query that creates the necessary schema, table content, set variables or creates files so the ground truth query can be executed successfully (setup_sql)
4. A SQL query that is used to validate whether the ground truth query and the predicted query have the same result or effect (validation_sql)

We run the benchmark as follows:
* We run the setup_sql query in databases A and database B
* We run the ground truth query in database A, and store the query result in table ddb_benchmark_result
* We run the predicted query in database B, and store the query result in table ddb_benchmark_result
* We run validation_sql in database A and database B, and compare their results

Here are some examples:

Question: Add a new column phone_numbers to the customers table, with array type varchar.
SQL: ALTER TABLE customers ADD COLUMN phone_numbers VARCHAR[];
Setup SQL: CREATE TABLE customers (customer_id varchar, firstname varchar); 
Validation SQL: DESCRIBE customers;

{2 more examples...}

Your task is to generate benchmark examples for {type} {name}. Make sure to generate queries for this particular functionality.

Now go ahead an think of good ways to probe a Text-2-SQL model for knowledge of this functionality. Make one easy (beginner knowledge), one medium (advanced knowledge), one hard (expert knowledge) question.

Here is some additional documentation for {type} {name}:

**Description:**
{description}

**Examples:**
{examples}

**Parameters:**
{parameters}

Text2SQL Prompt Template

We recommend the following prompt template for evaluations:

System Message:

You are an intelligent DuckDB SQL writing assistant. 
You only answer with a valid DuckDB SQL query, nothing else.

User Message:

[if {knowledge} not empty] 
    Here is some DuckDB SQL knowledge that may be relevant for the question:
    {knowledge}

Generate a valid DuckDB SQL query for the following task.

Assume that this operation was already executed:
{setup_sql}

Now the following task should be performed:
{question}

Generate the correct SQL query (use markdown code block):

Notes:

  • The {knowledge} placeholder is filled with relevant DuckDB documentation when using retrieval-augmented generation.
  • The {setup_sql} placeholder contains the SQL setup context needed for the query.
  • The {question} placeholder contains the natural language task description.

The prompt is structured as a two-message conversation with the LLM: a system message establishing the assistant's role, and a user message containing the actual query request with context.

FixIt Prompt Template

The following prompt template is used for SQL error correction:

System Message:

[system_prompt - configurable for the specific use case]

User Message:

[if retrieval enabled]
Here are some DuckDB SQL syntax specifics that may be helpful for fixing the query:
<docs>
[relevant documentation]
</docs>

Here is the user's database schema: 
[schema]

and there is the user's query:
[input_text]

Fix the following error: 
[error]

Make sure to maintain the current capitalization and use of line breaks, 
and keep in mind that trailing commas are usually allowed in DuckDB.

Notes:

  • The prompt includes optional retrieved DuckDB documentation relevant to the specific error.
  • The model receives the database schema to understand the table structure and relationships.
  • The original query with its error is provided for diagnosis and correction.
  • Instructions emphasize preserving the query style (capitalization, line breaks) while fixing the error.

Evaluation

The benchmark supports two documentation modes:

  1. No docs: Evaluate without any documentation context
  2. Distilled docs: Use LLM-distilled documentation with examples and parameter details

Results are compared using execution-based evaluation, allowing for column permutations and floating-point tolerance.

Citation

If you use this dataset, please cite:

@article{structured-docs-sql-2025,
  title={Structured Documentation for Dialect-Specific SQL Generation},
  author={MotherDuck},
  year={2025}
}
Downloads last month
11