csvsql without tty always tries to read stdin
Created by: scpike
The following snip works from a terminal but fails in a non-interactive session (we hit it in Jenkins, but I'd guess it also fails in cron)
csvsql --table foo --query "select * from foo" foo.csv
You get a StopIteration exception because csvsql is trying to read from stdin, which has nothing coming (this line: https://github.com/wireservice/csvkit/blob/205175fb70745b80db19acd4c314ad6c774b7fc0/csvkit/utilities/csvsql.py#L57). There's a previous discussion of the issue at https://github.com/wireservice/csvkit/issues/342 and https://github.com/wireservice/csvkit/issues/627, but the linked commit doesn't solve the issue.
We're working around it by always sending something in to stdin when running from a job.
I think csvsql should require naming stdin with a "-" when you want to read from both files named as arguments and stdin. This is how cat works:
echo "foo" | cat /tmp/file.csv  # just prints file.csv
echo "foo" | cat - /tmp/file.csv  # prints foo, then file.csv
echo "foo" | cat /tmp/file.csv -  # prints file.csv, then foo