Re: INSERT ... RETURNING as Oracle - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: INSERT ... RETURNING as Oracle
Date
Msg-id Pine.LNX.4.30.0103042101140.757-100000@peter.localdomain
Whole thread Raw
In response to INSERT ... RETURNING as Oracle  ("Sipos Andras" <s-andras-nospam4@freemail.hu>)
Responses Re: INSERT ... RETURNING as Oracle
List pgsql-general
Sipos Andras writes:

> create table basket (
>   id   serial  NOT NULL PRIMARY KEY,
>   timestamp  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
> );
>
> How can I make a one step insert into the table and get values of 'ID' ?
> I am trying to find a similar solution as in the oracle's INSERT ...
> RETURNING.

We have this sort of thing on the wish list, but it doesn't exist yet.
Some people feel it's better to calculate the default in the client
program and insert it explicitly.  This may be a reasonable alternative
for some applications.

> If I use at first the INSERT, and after SELECT MAX(ID), the result will be
> uncertain.

If you are worried about other transactions getting in the way then you
should do SET TRANSACTION ISOLATION LEVEL SERIABLIZABLE.

--
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/


pgsql-general by date:

Previous
From: "Sipos Andras"
Date:
Subject: INSERT ... RETURNING as Oracle
Next
From: Louis-David Mitterrand
Date:
Subject: Re: avoiding endless loop in an UPDATE trigger