Format Code Now
/
ConvertSQL INSERT to YAML Next: Tableizer ›

SQL INSERT to YAML Converter

CV-108

Paste INSERT ... VALUES statements and get a YAML list with one mapping per row, using the column names as keys.

Runs in your browser. Nothing is uploaded.

SQL INSERT statements (optional first line: -- table: name)

YAML

How to use it

  1. Paste your SQL INSERT statements.
  2. Pick the string escape style: Standard or MySQL.
  3. Press SQL to YAML.
  4. Copy the YAML or download the file.

How values are written

Strings are quoted only where YAML needs it, so a text value such as "007" or "true" stays quoted and is not turned into a number or boolean. Text with line breaks is written in double quotes with escapes. Numbers are written with the exact digits from the SQL, NULL becomes null, and TRUE and FALSE become booleans. Expressions such as NOW() are kept as text. Comments and anchors are not produced.

Tables and columns

With one table the output is a YAML list, one mapping per row. If the SQL inserts into several tables, each table name becomes a key above its list. Put -- table: name on the first line to pick one. Rows that name different columns are merged, with null for a column that was not given. Without a column list the keys are column_1, column_2 and so on. Statements other than INSERT ... VALUES are skipped.

Error messages and what to do

MessageWhat it meansFix
No INSERT ... VALUES statements foundThe text has no INSERT with a VALUES list.Paste INSERT INTO ... VALUES (...) statements.
Only INSERT ... VALUES is supported (INSERT ... SELECT, SET and DEFAULT VALUES are not) at line 1The INSERT takes its rows from a query or defaults.Use an INSERT with explicit VALUES.

Questions people ask

How do I convert SQL INSERT statements to YAML?

Paste the statements and press SQL to YAML. Each row becomes one item in a YAML list, with the column names as keys. Copy it or download the .yaml file.

Why are some values in quotes?

Strings that YAML would read as another type, such as "007", "true" or "null", are quoted so they stay text. Plain strings like Ada are written bare.

Are numbers rounded?

No. Numbers are written with the same digits as in the SQL. A 19-digit ID comes through untouched, though a YAML reader that loads it into a floating-point number may round it later.

Can it handle several tables?

Yes. Each table gets its own key with a list below it. To output one table only, put -- table: name on the first line of the input.

Does it execute my SQL?

No. The text is only read, never run, and there is no database involved anywhere. Statements that are not INSERT ... VALUES are skipped without a warning.

About this tool

Only INSERT ... VALUES statements are read, including multi-row inserts and the quoted-name styles of SQL Server, PostgreSQL and MySQL. Every other statement (CREATE TABLE, UPDATE, SET and so on) is skipped, and INSERT ... SELECT is an error. Without a column list the columns are named column_1, column_2 and so on. Numbers are kept digit for digit, so a 19-digit ID is not rounded. A value that is a function or expression, such as NOW() or CURRENT_TIMESTAMP, is kept as its text, since nothing is evaluated. One table gives a YAML list with one mapping per row; several tables give one key per table name, unless you pick one with -- table: name on the first line. Strings are quoted only where YAML needs it, so a text value such as "007" or "true" stays quoted and is not turned into a number; text with line breaks is written in double quotes with escapes. Numbers are written with the exact digits from the SQL, so large values are not rounded. NULL becomes null, TRUE and FALSE become booleans. Rows that name different columns are merged, with null for a column that was not given. The MySQL option reads backslash escapes inside strings. Comments are not produced.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.