Re: INSERT with a composite columnt from query

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Reg Me Please *EXTERN*" <regmeplease(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: INSERT with a composite columnt from query
Date: 2008-01-16 11:24:37
Message-ID: D960CB61B694CF459DCFB4B0128514C2CC2175@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Reg Me Please wrote:
> I have two table like these:
>
> create table compo (
> t text,
> i int
> );
>
> create table tab (
> x int,
> c compo
> );
>
> Then I have a function like this:
>
> create or replace function f_compo()
> returns setof compo as $body$
> ...
> $body$ language sql stable;
>
>
> What I'd need to do is to insert the results from f_compo() into
> the table TAB along with a value x.
>
> I expected somthing like this to work:
>
> insert into tab
> select 42,row( c.* ) from f_compo() c;
>
> But I get
> ERROR: cannot cast type record to compo

The whole exercise seems a bit pointless, but you could do it like this:

INSERT INTO tab SELECT 42, CAST (c AS compo) FROM f_compo() c;

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2008-01-16 11:25:59 Re: INSERT with a composite columnt from query
Previous Message Reg Me Please 2008-01-16 10:39:54 INSERT with a composite columnt from query