Skip to content

feat: add --null-value flag for custom NULL representation#184

Merged
vmvarela merged 1 commit into
masterfrom
issue-170/null-value-flag
Jul 3, 2026
Merged

feat: add --null-value flag for custom NULL representation#184
vmvarela merged 1 commit into
masterfrom
issue-170/null-value-flag

Conversation

@vmvarela

Copy link
Copy Markdown
Owner

Description

Add a --null-value flag that controls how SQL NULL values are rendered in CSV, TSV, and table output. JSON always uses native null regardless of the flag.

# Default: NULL renders as "NULL"
printf "name,score\nAlice,30\nBob,\n" | sql-pipe "SELECT * FROM t"
# → Alice,30
# → Bob,NULL

# Custom: replace with "N/A"
printf "name,score\nAlice,30\nBob,\n" | sql-pipe --null-value "N/A" "SELECT * FROM t"
# → Alice,30
# → Bob,N/A

# Empty string for downstream tools that treat blanks as NULL
printf "name,score\nAlice,30\nBob,\n" | sql-pipe --null-value "" "SELECT * FROM t"
# → Alice,30
# → Bob,

Changes

File Change
src/args.zig Parse --null-value <string> and --null-value=<string>
src/format.zig Thread null_value through CSV/TSV/JSON/XML writers
src/main.zig Pass null_value to table, markdown, and format writers
src/table.zig Table output uses configured null_value
src/markdown.zig Markdown output uses configured null_value
src/xml.zig XML output uses configured null_value
build.zig 122-line integration tests for null-value scenarios
README.md Custom NULL representation subsection + flags table entry
docs/sql-pipe.1.scd Option description + example in man page

Testing

All integration and unit tests pass:

zig build test    # 120+ bash-based integration tests — exit 0
zig build unit-test  # XML unit tests — exit 0
ziglint src build.zig  # No new violations

Closes

Closes #170

Implement a --null-value flag that lets users control how SQL NULL values
are rendered in CSV, TSV, and table output, while preserving native null
in JSON output.

- Parse --null-value in args.zig (--null-value <string>, --null-value=<string>)
- Thread null_value through format.zig, main.zig, table.zig, markdown.zig, xml.zig
- CSV/TSV renders null_value or default "NULL"
- Table output renders null_value or default "NULL"
- Markdown output uses null_value (default empty string)
- JSON always uses native null (flag has no effect)
- 122-line integration tests in build.zig covering CSV default, custom, and empty
- Update help text, README, and man page

Closes #170
@github-actions github-actions Bot added the type:feature New functionality label Jun 30, 2026
@vmvarela vmvarela merged commit fd377b4 into master Jul 3, 2026
5 checks passed
@vmvarela vmvarela deleted the issue-170/null-value-flag branch July 3, 2026 14:21
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 --null-value flag for custom NULL representation

1 participant