Re: INSERT ... RETURNING as Oracle

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Sipos Andras <s-andras-nospam4(at)freemail(dot)hu>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: INSERT ... RETURNING as Oracle
Date: 2001-03-04 20:04:02
Message-ID: Pine.LNX.4.30.0103042101140.757-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net http://yi.org/peter-e/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Louis-David Mitterrand 2001-03-04 20:08:39 Re: avoiding endless loop in an UPDATE trigger
Previous Message Oliver Elphick 2001-03-04 20:03:23 Re: INSERT ... RETURNING as Oracle