Re: mysql's last_insert_id

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Bo Lorentsen <bl(at)netgroup(dot)dk>
Cc: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>, Michal Adamczakk <pokryfka(at)artland(dot)com(dot)pl>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: mysql's last_insert_id
Date: 2003-08-29 02:11:09
Message-ID: 20030829021109.GB23834@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Aug 28, 2003 at 02:52:57PM +0200, Bo Lorentsen wrote:
> On Thu, 2003-08-28 at 10:02, Dennis Björklund wrote:
>
> > Yes, never use the oid at all is my suggestion.
> Hmm, will oid's not change so that they are unique regardless, or will
> oid be removed.

OIDs have never beebn unique, it's just that most databases never get big
enough to experience wraparound. They are also now optional per table and
may soon no longer be available by default.

> > If you need a unique id for a row then add a serial column that will
> > provide that, and use currval('the_sequence') to get the last inserted
> > value in that column for a session.
> This is just not a general solution to this problem, and will need
> awareness of the id type in the application layer.

There are various solutions. Some people use functions to do inserts, I just
use the string "currval(whatever)" in the application layer which the
database replaces with the appropriate value.

Whatever works for you.
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "All that is needed for the forces of evil to triumph is for enough good
> men to do nothing." - Edmond Burke
> "The penalty good people pay for not being interested in politics is to be
> governed by people worse than themselves." - Plato

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Browne, George (AT-Atlanta) 2003-08-29 02:23:18 How does it work
Previous Message Williams, Travis L, NEO 2003-08-29 02:03:25 Re: Join question