Skip to content

Add --schema flag to show inferred CREATE TABLE DDL #176

@vmvarela

Description

@vmvarela

Description

Add a --schema flag that prints the CREATE TABLE statement that sql-pipe inferred from the input data, without executing a query.

cat data.csv | sql-pipe --schema
# CREATE TABLE "t" (
#   "id" INTEGER,
#   "name" TEXT,
#   "amount" REAL,
#   "date" TEXT
# );

# With file arguments:
sql-pipe orders.csv customers.csv --schema
# CREATE TABLE "orders" (...)
# CREATE TABLE "customers" (...)

Motivation

Users frequently need to understand what sql-pipe "sees" from their data. Currently --columns --verbose shows types, but DDL output is more precise and allows users to understand affinity, see the exact schema, and even copy it into a persistent database. Especially useful for debugging type inference issues (e.g., why a column was detected as TEXT instead of INTEGER).

Acceptance Criteria

  • --schema flag is parsed in args.zig
  • After loading tables, query SELECT sql FROM sqlite_master WHERE type='table' and print each row
  • Works with multiple files (shows schema for each table)
  • --schema is mutually exclusive with --columns, --validate, --sample, --stats, --explain, and a query argument
  • Output goes to stdout (can be piped to a file)
  • Integration tests cover the new mode
  • Help text updated

Implementation Notes

  • Add SchemaArgs to src/args.zig following the pattern of ColumnsArgs/ValidateArgs
  • The existing getTableColumns function in src/sqlite.zig (line 277) already knows how to query PRAGMA table_info
  • The DDL query is trivially added: SELECT sql FROM sqlite_master WHERE type='table' AND name='<table>'

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