From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Marc Mamin <M(dot)Mamin(at)intershop(dot)de> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: row => text => row |
Date: | 2016-11-11 15:01:57 |
Message-ID: | 25592.1478876517@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Marc Mamin <M(dot)Mamin(at)intershop(dot)de> writes:
> It is possible to cast a row to text, but is there a way to revert that?
Well, you can surely cast it back to the rowtype, but I think that answer
doesn't really help you. What you seem to need is not casting to a
rowtype, but "bursting" the rowtype variable into individual columns.
> 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;
The trick here is to use the rowtype result as a single variable,
and burst it later:
regression=# create temp table test (like pg_class);
CREATE TABLE
regression=# with dummy as (select c from pg_class c limit 10)
regression-# insert into test select (c).* from dummy;
INSERT 0 10
BTW, I assume there's a reason for not simply doing
insert into test select * from pg_class c limit 10;
or even
with dummy as (select * from pg_class c limit 10)
insert into test select * from dummy;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2016-11-11 15:14:09 | Re: row => text => row |
Previous Message | Marc Mamin | 2016-11-11 08:55:52 | row => text => row |