Skip to content

feat: add SQL INSERT output format (-O sql)#187

Merged
vmvarela merged 3 commits into
masterfrom
issue-174/sql-insert-output-format
Jul 3, 2026
Merged

feat: add SQL INSERT output format (-O sql)#187
vmvarela merged 3 commits into
masterfrom
issue-174/sql-insert-output-format

Conversation

@vmvarela

@vmvarela vmvarela commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Add -O sql output format that generates INSERT INTO statements from query results. Useful for data migration between databases, seeding databases, and creating test fixtures.

Usage

$ printf 'name,age\nAlice,30\nBob,25\n' | sql-pipe -O sql 'SELECT * FROM t'
INSERT INTO "t" ("name", "age") VALUES ('Alice', 30);
INSERT INTO "t" ("name", "age") VALUES ('Bob', 25);

$ printf 'name\nO'"'"'Brien\n' | sql-pipe -O sql --sql-table users 'SELECT * FROM t'
INSERT INTO "users" ("name") VALUES ('O''Brien');

Changes

File Change
src/format.zig OutputFormat.sql, WriteOpts.sql_table, writeSqlRow() + writeSqlId/writeSqlStringLiteral helpers
src/args.zig ParsedArgs.sql_table, --sql-table flag, updated help text
src/main.zig sql_table wired through execQuery to OutputWriter
build.zig 9 integration tests
README.md -O sql and --sql-table documented
docs/sql-pipe.1.scd Man page updated

Value formatting

  • NULLNULL (unquoted)
  • INTEGER → raw decimal (42, -7)
  • FLOAT → raw, trunc check (30.030, 3.143.14)
  • TEXT → single-quoted with '' escaping
  • Identifiers double-quoted with "" escaping

Testing

  • zig build test — all pass (9 new SQL output tests)
  • zig build unit-test — all pass
  • Oracle plan review and final review both approved

Closes #174

Add -O sql output format that generates INSERT INTO statements per row,
with --sql-table flag for custom table name.

- OutputFormat.sql enum variant in format.zig
- writeSqlRow() with identifier quoting, string literal escaping,
  NULL handling, float truncation (matching JSON pattern)
- --sql-table flag parsing in args.zig (default: "t")
- sql_table wired through execQuery → OutputWriter
- 9 integration tests covering basic, custom table, escaping,
  NULL, numeric, float, empty, quoted columns, quoted table
- README.md and man page updated
@github-actions github-actions Bot added the type:feature New functionality label Jul 1, 2026
@vmvarela vmvarela merged commit 009376f into master Jul 3, 2026
4 checks passed
@vmvarela vmvarela deleted the issue-174/sql-insert-output-format branch July 3, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SQL INSERT output format (-O sql)

1 participant