Re: Last inserted id

From: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
To: pgsql-odbc(at)postgresql(dot)org
Subject: Re: Last inserted id
Date: 2001-11-12 10:36:19
Message-ID: AA30E7BCCA5C1D4E88A231900F8325C00C73@dogbert.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

> -----Original Message-----
> From: Jean-Michel POURE [mailto:jm(dot)poure(at)freesurf(dot)fr]
> Sent: 12 November 2001 10:06
> To: pgsql-odbc(at)postgresql(dot)org
> Subject: Re: [ODBC] Last inserted id
>
>
> At 09:55 12/11/01 +0000, you wrote:
> >'Cos that's not safe either - you might get multiple rows
> inserted at
> >the same time - unlikely, but certainly possible.
>
> In most cases a simple timestamp is enough because you add some other
> parameter to you query (ex:company name, or whatever field
> you inserted).
> For example, if you insert values with First_name=Dave,
> Second_name=Page,
> Timestamp=current time and query the resulting row, there is
> *very little*
> chance to get rows from other users.
>
> I guess this is the recommended way (see Access howto).

There is *very little* chance, but very little is not *no chance* (bear in
mind that at this point in time in the example we're discussing no primary
key value is yet known).

I would always suggest that people do a select nextval('seq') followed by a
suitable insert. It requires no locking, is definitely multi user safe and
will *always* correctly identify the row. The only downside is that it
requires a quick select before the insert, but if this minor speed sacrifice
was that much of an issue then VB+ADO+ODBC is possibly not the technology to
use in such a project anyway IMHO.

Regards, Dave.

Browse pgsql-odbc by date

  From Date Subject
Next Message Lucas Grijander 2001-11-12 14:12:42 Lotus Wordpro
Previous Message Jean-Michel POURE 2001-11-12 10:06:09 Re: Last inserted id