LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   i want to right the shell script which talk to my postgresql database (https://www.linuxquestions.org/questions/programming-9/i-want-to-right-the-shell-script-which-talk-to-my-postgresql-database-821471/)

dhirendrs 07-22-2010 06:51 AM

i want to right the shell script which talk to my postgresql database
 
Hi

I am new to this . i want to right the on linux box which have postgresql and i what some data from the different table and put it in .csv file.

dhiren

AnanthaP 07-22-2010 06:57 AM

Google for something like "access postgres with shell script". Dont forget the quotes (").

tonyfreeman 07-22-2010 10:11 PM

I believe you can do something like the following to output a csv file (<database> is the name of your database):

Code:

psql -A -q -t -F, -d <database> -o database.csv -c 'select * from table'
An even better way would be to use 'pg_dump', but it will output sql statements.

Have a look at the man page for pg_dump and find the '-T' option.

Here is an example: (<tablename> is the name of the table ... <database> is the name of the database):

Code:

pg_dump -T '<tablename>' <database> > mydb_table.sql


All times are GMT -5. The time now is 04:59 AM.