Skip to content

Add SQL INSERT output format (-O sql) #174

@vmvarela

Description

@vmvarela

Description

Add sql to the output format list. Generate SQL INSERT statements from query results.

sql-pipe data.csv -O sql 'SELECT * FROM t WHERE active = 1'
# INSERT INTO t (id, name, active) VALUES (1, 'Alice', 1);
# INSERT INTO t (id, name, active) VALUES (3, 'Carol', 1);

Motivation

Useful for data migration between databases, seeding databases, and creating test fixtures. Currently users must convert query output to INSERT statements manually.

Acceptance Criteria

  • Add sql to the OutputFormat enum in src/format.zig
  • Generate INSERT INTO <table> (<cols>) VALUES (<vals>); for each row
  • --sql-table <name> flag to specify target table name (default: "t")
  • String values quoted with single quotes, embedded single quotes escaped
  • NULL values rendered as NULL (no quotes)
  • Numeric values rendered without quotes
  • Boolean values rendered as 0/1 (SQLite convention)
  • Integration tests cover the new format
  • Help text updated

Implementation Notes

  • Similar to other output formatters in format.zig
  • Use writeJsonString-style escaping for SQL string values (adapt for single quotes)
  • About 40-50 lines of new code

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:mediumShould be done soonsize:sSmall — 1 to 4 hoursstatus:readyRefined and ready for sprint selectiontype:featureNew functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions