How to exclude the total row information from VSQL output
How to exclude the total row information from VSQL output
I am using VSQL to extract data from a table in CSV format using this command:
vsql -h [host_address] -d [db_name] -u [user_name] -w [password] -A -F , -t -f script_to_extract_data.sql -o output.csv
However, it outputs column headers, data rows AND an extra row that indicates the total number of rows in the table like this:
Geography,Product,Campaign,VariableName,Outlet,Creative,Period,VariableValue
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-03,24.06
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-08,67.17
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-17,404.67
(3 rows)
If I exclude the -t
option, it'll output just the data like this:
-t
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-03,24.06
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-08,67.17
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-17,404.67
I would like the column headers AND the data, but not the total row number like this:
Geography,Product,Campaign,VariableName,Outlet,Creative,Period,VariableValue
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-03,24.06
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-08,67.17
Geo_00000,Product,BABY,web_sales,Total,Total,2016-10-17,404.67
From reading through VSQL commandline options, I don't think I have a way to restrict the total number of rows not show?? Anyone who is experienced with using VSQL via commandline could help me out, I would greatly appreciate the help. Thank you!
2 Answers
2
There is no documented way to do this.
You could just inject a select into your script though to print out the header while leaving tuples-only on.
t
a
f ,
o output.csv
select 'Geography', 'Product', 'Campaign', 'VariableName', 'Outlet', 'Creative', 'Period', 'VariableValue';
select Geography, Product, Campaign, VariableName, Outlet, Creative, Period, VariableValue
from mytable;
o
And I guess if it really, really bothers you to list the fields twice, you could use a variable.
set fields Geography,Product,Campaign,VariableName,Outlet,Creative,Period,VariableValue
Then reference :fields
in both queries (just use '
around it for the header list). In this case, the header list would just need to be a string, and the delimiter would have to be a ,
since it would also be used in sql. Just a thought.
:fields
'
,
SELECT 'Geography, ....
No problem. You can also just list out the fields in strings which might be better in case you decide to change the delimiter in the future.
select 'Geography','Product' ...
In fact I do like that better so I'll change my answer.– woot
Dec 6 '16 at 14:06
select 'Geography','Product' ...
Without -t
add -P footer=off
...this will give you headers without the footer like you want.
-t
-P footer=off
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you! This hack of adding
SELECT 'Geography, ....
before is a great workaround! :)– user1330974
Dec 5 '16 at 15:13