Re: INSERT with a composite columnt from query

From: Richard Huxton <dev(at)archonet(dot)com>
To: Reg Me Please <regmeplease(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT with a composite columnt from query
Date: 2008-01-16 11:25:59
Message-ID: 478DE9C7.8090006@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Reg Me Please wrote:
>
> 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

You need to add an explicit cast I believe.

INSERT INTO tab (x,c)
SELECT 42, ROW(c.*)::compo FROM f_compo() c;

Why you don't in the case of INSERT ... VALUES isn't immediately clear
to me.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Schwarzer 2008-01-16 11:26:00 Re: Forgot to dump old data before re-installing machine
Previous Message Albe Laurenz 2008-01-16 11:24:37 Re: INSERT with a composite columnt from query