cannot use result of (insert .. returning)

Lists: pgsql-general
From: "dvs" <dvs(at)fon(dot)kamchatka(dot)ru>
To: <pgsql-general(at)postgresql(dot)org>
Subject: cannot use result of (insert .. returning)
Date: 2008-05-30 10:11:58
Message-ID: 013d01c8c23d$98594540$0e09a8c0@dvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hello,

I need to use query like:
select (insert into test (a) values (x) returning b),c from anytable
where condition
but it say
ERROR: syntax error at or near "into"

Is this a bug?

Function does not work too:
create function addt(..) returning .. as 'insert ... returning ..'
language 'sql'
ERROR:...
DETAIL: Function's final statement must be a SELECT.

BUT:
create function addt(..) returning .. as
'insert...(nextval('..')...);select currval('..')' language 'sql'
work in
select addt(x),c from anytable where condition

but this function is analog of "insert...returning" in any case
Why analog work "better" then original?
What is my mistake? (I dont want use functions here!)

dvs


From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: dvs <dvs(at)fon(dot)kamchatka(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cannot use result of (insert .. returning)
Date: 2008-05-31 06:53:31
Message-ID: 4840F5EB.4000301@wildenhain.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

dvs wrote:
> Hello,
>
> I need to use query like:
> ,c from anytable
> where condition
> but it say
> ERROR: syntax error at or near "into"

did you try with:

select (insert into test (a) values (x) returning b) query_a JOIN c ON ... ?

Tino.


From: "dvs" <dvs(at)fon(dot)kamchatka(dot)ru>
To: "Tino Wildenhain" <tino(at)wildenhain(dot)de>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: cannot use result of (insert .. returning)
Date: 2008-05-31 08:29:32
Message-ID: 012301c8c2f8$77be7e70$0e09a8c0@dvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

>> I need to use query like:
>> ,c from anytable where condition
>> but it say
>> ERROR: syntax error at or near "into"
>
> did you try with:
> select (insert into test (a) values (x) returning b) query_a JOIN c ON ...
> ?

you about
select * from (insert into test (a) values (x) returning b) z
?
it get the same error...