From: Neil Conway <neilc@samurai.com>
To: Michael Stone <mstone+postgres@mathom.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: insert without oids
Date: Fri, 13 Jan 2006 16:29:15 -0500
Message-ID: <1137187755.2509.6.camel@localhost.localdomain> (raw)
In-Reply-To: <20060113201011.GI1408@mathom.us>
References: <20060113201011.GI1408@mathom.us>
On Fri, 2006-01-13 at 15:10 -0500, Michael Stone wrote:
> OIDs seem to be on their way out, and most of the time you can get a
> more helpful result by using a serial primary key anyway, but I wonder
> if there's any extension to INSERT to help identify what unique id a
> newly-inserted key will get? Using OIDs the insert would return the OID
> of the inserted row, which could be useful if you then want to refer to
> that row in a subsequent operation. You could get the same result by
> manually retrieving the next number in the sequence and using that value
> in the insert, but at the cost of additional DB operations.
There's really no additional operations required:
INSERT INTO t1 VALUES (...);
INSERT INTO t2 VALUES (currval('t1_id_seq'), ...);
You need a separate SELECT if you want to use the generated sequence
value outside the database, although the INSERT ... RETURNING extension
will avoid that (there's a patch implementing this, although it is not
yet in CVS).
-Neil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: neilc@samurai.com, mstone+postgres@mathom.us
Subject: Re: insert without oids
In-Reply-To: <1137187755.2509.6.camel@localhost.localdomain>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox