Skip to content

Positional file arguments and multi-file joins #155

@vmvarela

Description

@vmvarela

Description

Accept files as positional arguments. Each file becomes a table named after its basename (sans extension). Stdin remains t.

Examples

# Single file — no more cat
sql-pipe orders.csv 'SELECT * FROM orders WHERE amount > 100'

# Multi-file join — the #1 reason people reach for DuckDB
sql-pipe orders.csv customers.csv \
  'SELECT c.name, SUM(o.amount) FROM orders o JOIN customers c ON o.cust_id = c.id GROUP BY c.name'

# Stdin still works, still called t
cat data.csv | sql-pipe 'SELECT * FROM t'

# Mix stdin + files
cat events.csv | sql-pipe users.csv 'SELECT * FROM t JOIN users ON t.uid = users.id'

Acceptance Criteria

  • Files passed as positional arguments are loaded as tables
  • Table names are derived from filenames (basename sans extension)
  • Stdin input is still available as table t
  • Multi-file joins work correctly
  • Input format is auto-detected from file extension (see related issue)
  • File-vs-query disambiguation works (heuristic: if arg is a readable file, treat as input; query is last non-file argument)
  • -- separator works for disambiguation if needed
  • All existing tests pass
  • New tests cover single-file, multi-file, stdin+file, and edge cases

Notes

  • This subsumes the "federated query" part of Database export and federated query support #70
  • Implementation: ~150 lines of Zig
  • Update args.zig to distinguish file paths from query string
  • Table naming: handle invalid SQL identifiers in filenames (quote or sanitize)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions