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.96k stars 73 forks source link

SELECT field,field with space FROM file.csv #32

Open elvarb opened 5 years ago

elvarb commented 5 years ago

It is impossible to select a field name that contains a space.

noborus commented 5 years ago

If the field name contains spaces, it must be enclosed in quotation marks. Quotation marks depend on the database driver.

SQLite 3 is double quotes (") and backquotes (`).

echo "i d,n a m e\n1,Alice"| trdsql -driver sqlite3 'SELECT "i d", "n a m e" FROM -'

and

echo "i d,n a m e\n1,Alice"| trdsql -driver sqlite3  'SELECT `i d`, `n a m e` FROM -'

postgres is a double quotation mark (").

echo "i d,n a m e\n1,Alice"| trdsql -driver postgres  'SELECT "i d", "n a m e" FROM -'

mysql is a backquotes (`).

echo "i d,n a m e\n1,Alice"| trdsql -driver sqlite3  'SELECT `i d`, `n a m e` FROM -'