-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"CREATE TABLE" does not append newline to header row in new CSV file. #22
Comments
First, the current behavior of csvq is as follows.
In the csvq, SELECT query is positioned as a statement that outputs the result and passes it to the outside. On the other hand, other queries do not do such a special processing because these queries complete operations within a transaction of csvq and do not link directly with the outside. If we strictly follow the posix standard, update queries should also append line breaks at the end of the files. However, line breaks are now often used as line separators rather than line endings, and I can't decide which behavior is better. At least, I think that adding a line break at the end of a file if needed is easier than removing a line break at the end of a file when not need. By the way, I don’t understand exactly what you want to do. Transaction management of csvq affects only operations with in the csvq processing, and the external commands should not be relevant. |
Does the POSIX standard specify this as a convention? RFC 4180 states that a line break (CRLF) is optional on the last line of a CSV file, but doesn't specify a line break is optional for the header row.
What is the difference between line separator and line ending in this context? What newline convention do other CVS processing tools follow? Is csvq consistent with these tools?
Yes, I agree.
I guess my point about transaction management is not relevant here because my examples mix |
Miller doesn't complain about empty CSV files that
Miller can also process non-empty CSV files that
Unlike |
The POSIX standard defines about a line as follows. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
The RFC 4180 defines about csv format as follows. https://tools.ietf.org/html/rfc4180
It’s header Line is as normal lines.
Csv is used by various tools including GUI as well as shell commands. It is not uncommon for users to write related processes themselves. |
Okay, then it seems as you pointed out earlier,
I must have missed this point in RFC 4180.
Users like me, for example. :)
Yes, I agree, but I think a CSV tool should at least try to follow the conventions that most tools follow. While |
csvkit also doesn't complain about CSV files that
By default, csvkit command
Like Miller, csvkit doesn't have a command to create a CSV file with a given a header. |
csvtool also doesn't complain about CSV files that
|
|
I changed my mind. The following changes will be implemented in the next release.
|
Thank you. This idea is a sensible compromise. |
#22]) With this change, the command option "--strip-ending-line-break" has been added.
Thank you for this fix! |
In the CSV file that it creates,
csvq
SQL statementCREATE TABLE
does not append a newline character to the header that it generates in the first row:Note that the
$
prompt immediately follows the last column name in the header instead of appearing on the next line becauseCREATE TABLE
does not append a newline character to the header row.As a consequence of this issue, should a program other than
csvq
append a data row to the new table without first appending a newline to the header (or prepending a newline to the data row), the data row will immediately follow the header on the same row:A simple workaround to this issue is to append a newline to the new CSV file after
CREATE TABLE
creates it, but before appending any data rows:Another solution would be to prepend each new data row with a newline, but omit the trailing newline:
Consistent with
CREATE TABLE
, SQL statementINSERT INTO
also follows this convention of prepending each data row with newline:To avoid this issue altogether, instead of using
CREATE TABLE
to create the CSV file and write the header row, we could "manually" create the file and write the header row with a trailing newline:There are several disadvantages to this manual approach:
The newline convention that
csvq
SQL statementsCREATE TABLE
andINSERT INTO
follows, while internally consistent, is not consistent with external shell commands.The text was updated successfully, but these errors were encountered: