dinedal / textql

Execute SQL against structured text like CSV or TSV
MIT License
9.07k stars 300 forks source link

Column name with "index" throws a syntax error #38

Closed AshwinJay closed 8 years ago

AshwinJay commented 9 years ago

Hi, this is a nice utility you've built, thanks.

I just wanted to let you know that header columns with name like "index" throws:

2014/12/29 12:00:22 near "index": syntax error

I renamed it from "index" to "fooindex" and it worked!

velppa commented 9 years ago

That's because it uses sqlite underneath and index is reserved word there.

awildeep commented 9 years ago

@schmooser This is easily a fixable behavior by creating the table with double quoted column names. EG:

sqlite> create table tbl ("index" string);
sqlite> .tables
tbl
sqlite> insert into tbl ("index") values ('1');
sqlite> select * from tbl;
1
sqlite> 

Of course this also requires a user to know that they need to double quote the column name in SQL as well, but at least the syntax error would no longer be an issue.

dinedal commented 8 years ago

This has been fixed in the latest version:

$ cat data2.csv
id,name,index
1,John,a
2,Jacob,b
3,Jingleheimer,c
4,schmidt,d
$ textql -header -sql 'select [index] from data2' data2.csv
a
b
c
d