Re: cannot use result of (insert .. returning)

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Dale Harris" <itsupport(at)jonkers(dot)com(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cannot use result of (insert .. returning)
Date: 2008-08-14 07:59:17
Message-ID: 162867790808140059n47d35b74r445b5fa74f2e0e43@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

you can wrap INSERT STATEMENT into function. Than you can do anything
with result;

create table f(a timestamp);

postgres=# select * from (insert into f values(current_timestamp)
returning *) x where x.a > now();
ERROR: syntax error at or near "into"
LINE 1: select * from (insert into f values(current_timestamp) retur...
^
create or replace function if() returns setof f as $$begin return
query insert into f values(current_timestamp) returning *; return;
end$$ language plpgsql;

postgres=# select * from if() where a > now();
a
---
(0 rows)

regards
Pavel Stehule

2008/8/14 Dale Harris <itsupport(at)jonkers(dot)com(dot)au>:
> Hello,
>
>
>
> I'm having the same issues as dvs had in message thread
> http://archives.postgresql.org/pgsql-general/2008-05/msg01117.php as I want
> to be able to use the result from an INSERT INTO table(...) VALUES(...)
> RETURNING new_row_ID.
>
>
>
> I would ideally like to be able to capture the RETURNING value into a
> variable to use immediately. Does anyone have a solution?
>
>
>
> Dale.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Александр Чешев 2008-08-14 08:21:26 PostgreSQL arrays and DBD
Previous Message Dale Harris 2008-08-14 07:18:09 Re: cannot use result of (insert .. returning)