Saving a vertica query to a file from the vsql prompt

Document ID : KB000011913
Last Modified Date : 14/02/2018
Show Technical Document Details
Question:

What is the syntax to save a vertica query to a file when run from the vsql prompt and without logging into adminTools?

Environment:
CAPM 2.x
Answer:

To save a vertica query to a file when run from the vsql prompt and without logging into adminTools you can do the following:

 

1. Log on to the data repository

2. Change to the dradmin user (su - dradmin)

3. cd /opt/vertica/bin

4. Run the following query:

./vsql -U<user> -w<password> -c 'query;' > /tmp/filename.txt

 

Example:

./vsql -Udradmin -wdbpass -c 'select database_name from databases;' > /tmp/database.txt

 

Output: 

cat /tmp/database.txt

 database_name

---------------

 drdata

(1 row)