guide/sql
SQL (sql-*)
A file can carry the SQL that goes with it — the CREATE TABLE, the keys and indexes, the query that produced the data. Ship the data and the recipe together.
txtab
# sql-pre-data postgres CREATE TABLE orders (id bigint PRIMARY KEY, customer_id bigint, amount numeric(12,2))
# sql-post-data postgres ALTER TABLE orders ADD FOREIGN KEY (customer_id) REFERENCES customers(id)
# sql-post-data postgres CREATE INDEX orders_customer ON orders(customer_id)
# sql-dql postgres SELECT * FROM orders WHERE created_at >= '2026-10-01'Before and after the data
The split is the one pg_dump uses:
sql-pre-data— what must exist before rows go in: tables, schemas, types, extensions.sql-post-data— what is better added after: indexes, primary and foreign keys, constraints, triggers.sql-dql— queries kept for the record. Never run.
Loading goes: every sql-pre-data in file order → the data → every sql-post-data in file order. That's faster (indexes are built once) and order-proof: a foreign key from orders to customers can sit in the orders block even though customers comes later in the file.
Dialects
The first word after the keyword is always the database: postgres, mysql, clickhouse, sqlite, duckdb, mssql, oracle, snowflake, bigquery, … — or ansi for standard SQL. Add a version when it matters: postgres-17, mysql-8.4. Ship the same table for several databases side by side; each consumer takes theirs.
bash
txtab sql postgres data.txtab | psql
txtab sql postgres --section post-data data.txtabTools only print SQL; they never connect to your database. One line holds one statement.
SQL in the file block
Statements before the first table belong to the whole file — CREATE SCHEMA, CREATE EXTENSION. Statements in a table block belong to that table.