dinedal / textql

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

Infinite loop generating newlines with semicolon and newline in the query #105

Open v-from-meiro opened 6 years ago

v-from-meiro commented 6 years ago

Hello there!

I was working on a query and using textql (by the way, great job, thanks for this!) and noticed funny thing.

Usually the command I am using looks like this:

textql -header -output-header -sql "select distinct ex_account_id as account_id , substr( end_time ,1,10) as date , group_concat(case when name ='page_views_total' and period ='day' then value end) as page_views , group_concat(case when name ='page_fan_adds' and period ='day' then value end) as page_fan_adds , group_concat(case when name ='page_fan_removes' and period ='day' then value end) as page_fan_removes , group_concat(case when name ='page_impressions_unique' and period ='day' then value end) as page_reach , group_concat(case when name ='page_fans' and period ='lifetime' then value end) as page_fans from page_insights as pi group by ex_account_id , date " page_insights.csv

Now when you run it is all OK. But check what happens when you put semicolon followed by newline in the end of the query:

textql -header -output-header -sql "select distinct ex_account_id as account_id , substr( end_time ,1,10) as date , group_concat(case when name ='page_views_total' and period ='day' then value end) as page_views , group_concat(case when name ='page_fan_adds' and period ='day' then value end) as page_fan_adds , group_concat(case when name ='page_fan_removes' and period ='day' then value end) as page_fan_removes , group_concat(case when name ='page_impressions_unique' and period ='day' then value end) as page_reach , group_concat(case when name ='page_fans' and period ='lifetime' then value end) as page_fans from page_insights as pi group by ex_account_id , date; " page_insights.csv

When you run it, textql gets probably into an infinite loop and starts to generate a bunch of newlines in the end of an actual result. I ran this without knowing on a server an it crashed in few minutes because of disk space :-D

Let me know if it is just me or you too have this problem :)

Thanks and have a great day!

v-from-meiro commented 6 years ago

I just noticed it removed the newline after the semicolon in the second query. So, please, add a newline just after the semicolon in a second query to reproduce the error.

manveru commented 3 years ago

Just wanted to say thanks, stumbled over this issue today as well.