Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to export each row of a view to seperate files

Status
Not open for further replies.

utahstew

Technical User
Oct 11, 2010
1
US
I have a unique need.

I need to export script to export each row of a postgres view to individual files.

OS: Red hat 9
Language: Shell script or java

Column A - is used for the filename.
Column B - is the contents of the file.

I am not a linux programmer, I focus on database design.I assume the script is like this:

Open array
for each row in view
open file where name equals column a
contents equals column b
close file
next
close array

Any help in this matter is appreciated.
 
Hi

utahstew said:
Column B - is the contents of the file.
Column type ?

By default it would be one line if you are working only with text files :
Code:
psql -t -A -c 'select filename from utahstew' | while read file; do psql -t -A -c "select content from utahstew where filename='$file'" > "$file"; done
Note that you may need to add connection and credential parameters to the [tt]psql[/tt] calls.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top