neurondb-ai/neurondb-postgresql-sql
NeuronDB PostgreSQL SQL & PL/pgSQL Instruction Dataset
A large-scale, curated instruction dataset for training and evaluating LLMs on PostgreSQL-specific SQL and PL/pgSQL generation. Every row is a (question, schema, SQL) triplet with rich metadata for filtering and analysis.
Dataset Summary
Splits
Schema
Each row contains 11 fields:
Sources
Data is aggregated from multiple high-quality sources, each tagged:
Source Descriptions
- `postgresql_regression_tests` — SQL extracted from PostgreSQL's own regression test suite
- `postgresql_docs` — Examples from official PostgreSQL SGML documentation
- `postgresql_contrib` — SQL from contrib modules (pg_trgm, hstore, ltree, etc.)
- `pgtap_tests` — pgTAP unit test SQL
- `plpgsql_source` — PL/pgSQL functions from the PostgreSQL source tree
- `pgbench_scripts` — pgbench benchmark scripts
- `handcrafted_advanced` — Hand-written examples covering advanced patterns (window functions, CTEs, JSONB, RLS, triggers, partitioning, custom aggregates, etc.)
- `sql_create_context` — WikiSQL/Spider-derived text-to-SQL pairs (b-mc2/sql-create-context)
- `synthetic_text_to_sql` — Synthetically generated text-to-SQL pairs (gretelai, NumbersStation)
- `community_sql_datasets` — Other community SQL datasets (Clinton/text-to-sql-v1, knowrohit07/know_sql)
Difficulty Distribution
Categories
Usage
from datasets import load_dataset
ds = load_dataset("neurondb/neurondb-postgresql-sql")
# Filter for advanced PostgreSQL-specific queries
advanced_pg = ds["train"].filter(
lambda x: x["difficulty"] == "advanced" and x["is_postgresql_specific"]
)
# Filter by category
window_fns = ds["train"].filter(lambda x: x["category"] == "query_window_function")
# Filter by source
gold = ds["train"].filter(
lambda x: x["source"] in [
"postgresql_regression_tests",
"postgresql_docs",
"handcrafted_advanced",
]
)Intended Use
- Fine-tuning LLMs for PostgreSQL SQL and PL/pgSQL code generation
- Evaluating text-to-SQL models on PostgreSQL-specific syntax
- Benchmarking SQL generation quality across difficulty levels
- Building PostgreSQL-aware coding assistants
Data Quality
- All rows have non-empty
questionandsqlfields - MySQL-only and T-SQL-only syntax has been filtered out
- Duplicate (question, SQL) pairs have been removed
- Rows with trivially short SQL (< 10 chars) are excluded
- Each row is tagged with source, difficulty, and category for easy filtering
Examples
Example 1 — basic / query_select
Source: sql_create_context
Question: Generate PostgreSQL SQL for: Which manufacturer made a locomotive with a type of 4-6-4t?
Schema:
CREATE TABLE table_name_40 (manufacturer VARCHAR, type VARCHAR)SQL:
SELECT manufacturer FROM table_name_40 WHERE type = '4-6-4t';Example 2 — intermediate / query_join
Source: community_sql_datasets
Question: What is the average account balance for customers who have a Shariah-compliant mortgage or a socially responsible loan?
Schema:
CREATE TABLE shariah_mortgages (mortgage_id INT, customer_id INT, account_balance DECIMAL); CREATE TABLE socially_responsible_loans (loan_id INT, customer_id INT, account_balance DECIMAL); CREATE TABLE shariah_loans (loan_id INT, mortgage_id INT);SQL:
SELECT AVG(CASE WHEN sm.customer_id IS NOT NULL THEN sm.account_balance ELSE srl.account_balance END) FROM shariah_mortgages sm RIGHT JOIN socially_responsible_loans srl ON sm.customer_id = srl.customer_id JOIN shariah_loans sl ON sm.mortgage_id = sl.mortgage_id OR srl.loan_id = sl.loan_id;Example 3 — advanced / plpgsql_function
Source: community_sql_datasets
Question: Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 352).
SQL:
$$ language plpgsql;
select * from sc_test();
create or replace function sc_test() returns setof integer as $$
declare
c refcursor;Explanation: PL/pgSQL object from PostgreSQL core test for Plpgsql.
Example 4 — advanced / querywindowfunction
Source: community_sql_datasets
Question: What is the difference in the number of attendees for each community education program between the first and last occurrence?
Schema:
CREATE TABLE community_education (program_name VARCHAR(255), location VARCHAR(255), date DATE, num_attendees INT); INSERT INTO community_education (program_name, location, date, num_attendees) VALUES ('Wildlife Awareness', 'New York', '2020-01-01', 50), ('Wildlife Awareness', 'Florida', '2020-03-10', 75), ('Nature Walk', 'California', '2019-05-15', 25), ('Nature Walk', 'California', '2020-05-15', 35);SQL:
SELECT program_name, num_attendees - FIRST_VALUE(num_attendees) OVER (PARTITION BY program_name ORDER BY date) as diff FROM community_education;Citation
If you use this dataset, please cite:
@dataset{neurondb_postgresql_sql_2026,
title={NeuronDB PostgreSQL SQL & PL/pgSQL Instruction Dataset},
author={NeuronDB Team},
year={2026},
url={https://huggingface.co/datasets/neurondb/neurondb-postgresql-sql},
}License
Apache 2.0
