Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Vertica query result to csv file

I`m working with Vertica. I try to export data from SELECT query into csv. I tried making it with sql query:

SELECT * FROM table_name INTO OUTFILE '/tmp/fileName.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

I got an error:

[Vertica][VJDBC](4856) ERROR: Syntax error at or near "INTO"

Is there a way to export a query result to a csv file? I prefer not to use vsql, but if there no other way, I will use it. I tried the following:

vsql -c "select * from table_name;" > /tmp/export_data.txt
like image 713
Opperix Avatar asked Oct 21 '14 07:10

Opperix


2 Answers

Here is how you do it:

vsql -U dbadmin -F ',' -A -P footer=off -o dumpfile.txt -c "select ... from ... where ...;"

Reference: Exporting Data Using vsql

like image 58
Marcus Couto Avatar answered Nov 01 '22 23:11

Marcus Couto


Accordingly to https://my.vertica.com/docs/7.1.x/HTML/Content/Authoring/ConnectingToHPVertica/vsql/ExportingDataUsingVsql.htm

=> SELECT * FROM my_table;
 a |   b   | c
---+-------+---
 a | one   | 1
 b | two   | 2
 c | three | 3
 d | four  | 4
 e | five  | 5
(5 rows)
=> \a
Output format is unaligned.
=> \t
Showing only tuples.
=> \pset fieldsep ','
Field separator is ",".
=> \o dumpfile.txt
=> select * from my_table;
=> \o
=> \! cat dumpfile.txt
a,one,1
b,two,2
c,three,3
d,four,4
e,five,5
like image 29
fl00r Avatar answered Nov 01 '22 22:11

fl00r