Re: Exporting 1 text column from all rows from a table to a file per row?

Поиск
Список
Период
Сортировка
От Ondrej Ivanič
Тема Re: Exporting 1 text column from all rows from a table to a file per row?
Дата
Msg-id CAM6mieLVN0gDbmt1sZCoqPzwjOO_-3LfbhAe+3uJZg_+695+ew@mail.gmail.com
обсуждение исходный текст
Ответ на Exporting 1 text column from all rows from a table to a file per row?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
Список 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 по дате отправления:

Предыдущее
От: Jerry Sievers
Дата:
Сообщение: Re: Exporting 1 text column from all rows from a table to a file per row?
Следующее
От: Twaha Daudi
Дата:
Сообщение: Installing postgresql on windows 7