Re: Exporting 1 text column from all rows from a table to a file per row? - Mailing list pgsql-general

From Ondrej Ivanič
Subject Re: Exporting 1 text column from all rows from a table to a file per row?
Date
Msg-id CAM6mieLVN0gDbmt1sZCoqPzwjOO_-3LfbhAe+3uJZg_+695+ew@mail.gmail.com
Whole thread Raw
In response to Exporting 1 text column from all rows from a table to a file per row?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
List pgsql-general
Hi,

On 22 November 2011 06:10, Joost Kraaijeveld <J.Kraaijeveld@askesis.nl> wrote:
> Is it possible, and if so how, to export a single column of a table into
> a separate file per row? I have a table with ~21000 rows that have a
> column "body1" containing ASCII text and I want to have 21000 separate
> ASCII files, each containing that column "body1". The name of the file
> does not matter, although it would be nice if they had the extension
> "txt".

Something like this could do the job:

for i in `psql -a -t -c 'select id from T'`; do psql -a -t -c "select
body1 from T where id = $i" -o $i.txt; done;

where 'T' is your table and 'id' is primary column in that table. I've
omitted connection options (-h -U ...) from psql commands.

--
Ondrej Ivanic
(ondrej.ivanic@gmail.com)

pgsql-general by date:

Previous
From: Jerry Sievers
Date:
Subject: Re: Exporting 1 text column from all rows from a table to a file per row?
Next
From: Twaha Daudi
Date:
Subject: Installing postgresql on windows 7