Generate basic INSERT statements automatically from PostgreSQL CREATE TABLE DDL.
This tool analyzes table definitions and foreign key relationships, then generates sample INSERT SQL for testing or development environments.
DDL:
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
customer_name VARCHAR(50)
);Generated INSERT:
INSERT INTO customers (customer_id, customer_name)
VALUES (1, 'customer_name_1');- Parse PostgreSQL CREATE TABLE DDL
- Analyze primary and foreign key relationships
- Generate basic INSERT statements
- CLI-based usage
- CTE-based INSERT generation
- Identity-aware insert chaining
- Dependency handling
ddl2insert_gen
├ src
│ └ ddl2insert.py
├ example
│ ├ schema.sql
│ ├ column_value_config.json
│ ├ run_example.sh
│ └ output
│ ├ mountain_01.sql
│ ├ mountain_02.sql
│ └ column_template.json
├ README.md
├ LICENSE
└ requirements.txt
Example input file:
example/schema.sql
Example output files:
example/output/mountain_01.sql
example/output/mountain_02.sql
python src/ddl2insert.py example/schema.sql
Windows users can also run:
py src/ddl2insert.py example/schema.sql
You can also run the helper script:
sh example/run_example.sh
The file column_value_config.json can be edited to customize the
values used when generating INSERT statements.
You can specify values for each column.
The tool also generates a file named output/column_template.json,
which contains detected columns and sample values.
You can use this file as a template to create or update
column_value_config.json.
- Run the tool once to generate
output/column_template.json - Copy or rename
output/column_template.jsontocolumn_value_config.json - Edit the
VALUESfield to control generated data - Run the tool again
- If a value is defined in
VALUES, that value will be used - If
VALUESis empty, the system automatically generates a sample value based on the column type - Columns without configuration are not affected
{
"COLUMN": "is_deleted",
"TYPE(S)": "boolean",
"VALUES": [false]
}Run the tool with the example schema:
python src/ddl2insert.py example/schema.sql
Generated SQL files will appear in the example/output directory.
Alternatively, run the helper script:
sh example/run_example.sh
Currently supported elements:
- CREATE TABLE
- PRIMARY KEY
- FOREIGN KEY
Support for additional PostgreSQL features will be added in future updates.
DDL
↓
Parser
↓
Column Template JSON (output/column_template.json)
↓
User Configuration (column_value_config.json)
↓
INSERT SQL Generation
This project is licensed under the MIT License.
See the LICENSE file for details.