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

From: Jerry Sievers <gsievers19(at)comcast(dot)net>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Exporting 1 text column from all rows from a table to a file per row?
Date: 2011-11-21 21:51:23
Message-ID: 878vn9nnz8.fsf@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl> writes:

> Hi,
>
> 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".

run a script like this and save to a file that you will later run sh
on...

psql -Atqf thatscript >sh_commands

create temp sequence s;

select 'cat <<! >' || nextval('s')::text || '.txt
' || somefield || '
!'
from sometable;

> TIA
>
> --
> Groeten,
>
> Joost Kraaijeveld
> Askesis B.V.
> Molukkenstraat 14
> 6524NB Nijmegen
> tel: 024-3888063 / 06-51855277
> fax: 024-3608416
> web: www.askesis.nl
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres(dot)consulting(at)comcast(dot)net
p: 305.321.1144

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ondrej Ivanič 2011-11-21 22:01:43 Re: Exporting 1 text column from all rows from a table to a file per row?
Previous Message Jason Long 2011-11-21 19:44:26 Re: Supply Chain Calcs