Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Helps make long SQL INSERT statements readable

Project Description
# sql_insert_writer

[![PyPI Status](](
[![Code Climate](](
[![Test Coverage](](
[![Dependency Status](](

Helps generate highly readable SQL INSERT statements

Calling with one table name creates an `INSERT INTO... VALUES` statement:

$ sql_insert_writer pet

DEFAULT, -- ==> id
DEFAULT, -- ==> name
DEFAULT, -- ==> species_name
DEFAULT, -- ==> planet
DEFAULT -- ==> kg

If more table names are added, will generate an `INSERT INTO... SELECT FROM`
statement, matching as many column names as it can between the destination
and source table(s):


$ sql_insert_writer pet animal

id, -- ==> id
name, -- ==> name
species_name, -- ==> species_name
planet, -- ==> planet
DEFAULT -- ==> kg
FROM animal

## More usage examples

## Rationale

The syntax of `INSERT` statements makes it difficult to tell which destination columns a value is intended for,
especially in inserts with many columns. (Our five-column example is not bad, but imagine fifty columns!)

Comments can clarify the link between data source and destination, but adding those comments manually is tedious and error-prone.

Explicitly listing the destination columns of an `INSERT` is another best practice often skipped due to tedium.

The output of `sql_insert_writer` will rarely be fully ready to execute, but it should save the bulk of the typing.

## Features

- Supports PostgreSQL, SQLite, MySQL
- Accepts [SQLAlchemy database URLs]( with `--db` option. Defaults to environment variable `$DATABASE_URL`.
- Any number of source tables; columns chosen in order specified
- Any number of tuples in `VALUES` clause with `--tuples` option
- Explicitly cast to destination column type with `--cast` option

## Installation

[Installation instructions](docs/installation.rst)

Development installation instructions, so that
you can modify the code and contribute your
improvements back to the project, are included
in the [CONTRIBUTING documentation](CONTRIBUTING.rst).

## Planned features

- Support for more databases
- Approximate column name matches
- Omit inserts into auto-incrementing primary key columns
- Pre-fill JOIN clauses with foreign keys where possible

## Limitations

We do not deal well with case-sensitive table or column names; for lo, they are an abomination unto Codd.

## Credits

This package was created with [Cookiecutter](
and the [18F/cookiecutter-pypackage](
project template.

## Public domain

This project is in the worldwide [public domain]( As stated in [CONTRIBUTING](CONTRIBUTING.rst):

> This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the [CC0 1.0 Universal public domain dedication](
> All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.


0.1.0 (2017-10-12)

* First release on PyPI.

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sql_insert_writer-0.1.0-py2.py3-none-any.whl (9.4 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Oct 12, 2017
sql_insert_writer-0.1.0.tar.gz (11.6 kB) Copy SHA256 Checksum SHA256 Source Oct 12, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting