LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-22-2010, 06:51 AM   #1
dhirendrs
Member
 
Registered: Nov 2009
Posts: 45

Rep: Reputation: 15
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
 
Old 07-22-2010, 06:57 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Google for something like "access postgres with shell script". Dont forget the quotes (").
 
Old 07-22-2010, 10:11 PM   #3
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
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
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to insert value in database deepu_linux Programming 14 04-25-2013 12:07 PM
shell script to back up a postgresql database divyasmk Linux - General 1 06-04-2010 02:13 AM
Database connection using Shell Script sumitarun Linux - Newbie 2 05-09-2010 12:18 PM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
PostgreSQL shell script help, please marktaff Linux - General 0 11-10-2001 03:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration