SmartQueryTools

Convert YAML to SQL Online

Convert YAML files to SQL INSERT statements directly in your browser. Copy or download the generated SQL — no upload required.

About converting YAML to SQL

YAML fixtures and seed files are common in Rails, Django and many test suites. Converting them to SQL gives you a script you can run with psql, the sqlite3 shell or any database client. That is useful for loading the same seed data outside the framework, or for handing it to someone who works directly in the database.

The script starts with CREATE TABLE IF NOT EXISTS, with one column per YAML key. It then has one INSERT statement per record, up to the first 1,000 records. The table name is the file name with non-alphanumeric characters replaced, so users.yml creates a table named "users". Integer keys become BIGINT, decimals DOUBLE PRECISION, booleans BOOLEAN, quoted ISO dates DATE and everything else TEXT.

Relational tables are flat, so nested YAML does not fit. Nested mappings and lists are written into TEXT columns as JSON strings. Flatten the YAML first, or split nested lists into a separate table yourself. Rails-style fixtures keyed by name, where the top level is a mapping of record names, produce a single row. Convert them to a list of records before using this tool.

Worked example

A small orders export with an ID, a customer name, a date, an amount (one missing) and a true/false flag, converted with the default settings.

Input (YAML)

- order_id: 1001
  customer: Acme Ltd
  order_date: '2026-03-02'
  amount: 249.5
  shipped: true
- order_id: 1002
  customer: Brightside Co
  order_date: '2026-03-02'
  amount: 1200
  shipped: false
- order_id: 1003
  customer: Acme Ltd
  order_date: '2026-03-05'
  amount: 89.99
  shipped: true
- order_id: 1004
  customer: Northwind
  order_date: '2026-03-07'
  amount: null
  shipped: false

Output (SQL)

CREATE TABLE IF NOT EXISTS "data" (
  "order_id" BIGINT,
  "customer" TEXT,
  "order_date" DATE,
  "amount" DOUBLE PRECISION,
  "shipped" BOOLEAN
);

INSERT INTO "data" VALUES (1001, 'Acme Ltd', '2026-03-02', 249.5, true);
INSERT INTO "data" VALUES (1002, 'Brightside Co', '2026-03-02', 1200, false);
INSERT INTO "data" VALUES (1003, 'Acme Ltd', '2026-03-05', 89.99, true);
INSERT INTO "data" VALUES (1004, 'Northwind', '2026-03-07', NULL, false);

What changes when you convert YAML to SQL

  • The CREATE TABLE statement lists every key, with a type chosen from its values.
  • order_id becomes BIGINT, amount DOUBLE PRECISION, shipped BOOLEAN and the quoted order_date DATE.
  • Each YAML record becomes one INSERT statement, and text values are single-quoted with apostrophes doubled.
  • null and missing keys become NULL, as for order 1004's amount.
  • Records after the first 1,000 are left out, and the page shows a notice when that happens.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Frequently Asked Questions

Can I convert Rails fixtures to SQL?

Only after reshaping. Rails fixtures are a mapping of fixture names to records, which this converter reads as a single row. Rewrite the file as a list of records, adding the fixture name as a field if you need it, then convert.

Why is there a 1,000 record limit?

The SQL is built and shown as text in the page, and very long scripts of single INSERTs are slow to render and to run. For more records, convert the YAML to CSV and load it with your database's bulk import command.

Which databases can run the script?

PostgreSQL, SQLite and DuckDB run it as written. MySQL needs ANSI_QUOTES enabled or backticks in place of the double-quoted names. SQL Server needs more changes, because it has no BOOLEAN type and no CREATE TABLE IF NOT EXISTS.

What is SQL format?

SQL (Structured Query Language) is the standard language for querying and manipulating relational databases. The output contains CREATE TABLE and INSERT INTO statements ready to run against any SQL-compatible database.

Related Tools