Skip to main content

Loading data from table to file

  • September 23, 2013
  • 5 replies
  • 19 views

harish_babu_yar
Forum|alt.badge.img+1
i need to load data from a table to csv but with in a single command i need to acheive this . so please suggest me an way to do this using vsql command. Thanks

5 replies

Rajasekhar_1
  • New Participant
  • September 23, 2013
Hii Harish, You can do it by using \o command. Eg: i have a table named TEST_TABLE now i want to generate a comma separated data from this table. for that do as follows.. \o /home/dbadmin/TEST_TABLE.txt; select * from TEST_TABLE; DONE!! Now search the file in the path /home/dbadmin Regards, Raj!!!

Rajasekhar_1
  • New Participant
  • September 23, 2013
Harish, Prior to the above statements, you need to do some file alignment settings. \a for alignment \f for separator Eg: comma, pipe, tab Regards, Raj

Prasanta_Pal
Forum|alt.badge.img
  • Participating Frequently
  • September 23, 2013
From unix prompt $/opt/vertica/bin/vsql -U dbadmin -A -t -F'|' -h -c "select * from " > /tmp/export.txt

harish_babu_yar
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • October 3, 2013
but for the dbadmin it will be asking for password i want the password also encrypted in the same command.

> vsql -U username -F $'\t' -At -o dumpfile.txt -c "SELECT * FROM my_table;"
Password:
i want to enter the password also in the same command.
My scenario this command fires on vertica db through a jdbc driver. for that i am writing a shell script to open vsql and fire this query and come out of vsql


Navin_C
Forum|alt.badge.img+2
  • Participating Frequently
  • October 3, 2013
use this from unix terminal
vsql -U username -w password -F $'\t' -At -o dumpfile.txt -c "SELECT * FROM my_table;"
Hope this helps.