noborus / trdsql

CLI tool that can execute SQL queries on CSV, LTSV, JSON, YAML and TBLN. Can output to various formats.
https://noborus.github.io/trdsql/
MIT License
1.94k stars 73 forks source link

"null" representation #182

Closed agguser closed 2 years ago

agguser commented 2 years ago

Please add options to specify null representation (e.g. -in _, -on _ to use underscores as nulls in input, ouput (in the same way as -id, -od for delimiter)).

It seems that, for output, null and empty string cannot be differentiate; and there is no way to specify null in input.

$ trdsql 'select 1,null,2,"",3'
1,,2,,3

$ echo '1,,2,,3' | trdsql 'select coalesce(c2,"null"),iif(c4=="","empty", c4) from -'
,empty

A workaround is to do it manully, e.g. with coalesce, nullif, but it is tedious to do so for all columns.

$ trdsql 'select 1,coalesce(null, "_"),2,"",3'
1,_,2,,3

$ echo '1,_,2,3' | trdsql 'select coalesce(nullif(c2,"_"), "NULL") from -'
NULL
noborus commented 2 years ago

Thank you for a good issue. I think this can be implemented.