Re: row => text => row

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: row => text => row
Date: 2016-11-11 15:14:09
Message-ID: acb581aa-e43b-cb10-9c1a-abd47f3d4093@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/11/2016 12:55 AM, Marc Mamin wrote:
> Hello,
>
> It is possible to cast a row to text, but is there a way to revert that?
>
> e.g.:
>
> create temp table test like pg_class;
>
> WHITH dummy as (SELECT (c.*)::text t from pg_class c limit 10)
> INSERT INTO test
> SELECT ???
> FROM dummy;
>
>
> an other option that would sometimes help me would be to cast rows as
> text,but in their (default) csv representation:
>
> select to_csv((c.*)) from foo c;

In psql(https://www.postgresql.org/docs/9.5/static/app-psql.html):

Long way

\pset fieldsep ','
\pset format unaligned
\pset footer
\o test.csv
SELECT (c.*) t from pg_class c limit 10;
\o

Shorter way:

\copy { table [ ( column_list ) ] | ( query ) } { from | to } {
'filename' | program 'command' | stdin | stdout | pstdin | pstdout } [ [
with ] ( option [, ...] ) ]

Outside psql:

https://www.postgresql.org/docs/9.5/static/sql-copy.html

>
> regards,
>
> Marc Mamin
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Brandl 2016-11-11 15:30:50 Change column type from int to bigint - quickest way
Previous Message Tom Lane 2016-11-11 15:01:57 Re: row => text => row