Re: Last inserted id - Mailing list pgsql-odbc

From Dave Page
Subject Re: Last inserted id
Date
Msg-id AA30E7BCCA5C1D4E88A231900F8325C00C71@dogbert.vale-housing.co.uk
Whole thread Raw
In response to Last inserted id  ("Simeo Reig" <simreig@terra.es>)
List pgsql-odbc

> -----Original Message-----
> From: Geoffrey D. Bennett [mailto:g@netcraft.com.au]
> Sent: 12 November 2001 08:55
> To: Dave Page
> Cc: 'Simeo Reig'; 'pgsql-odbc@postgresql.org'
> Subject: Re: [ODBC] Last inserted id
>
>
> On Mon, Nov 12, 2001 at 08:23:08AM -0000, Dave Page wrote:
> > > -----Original Message-----
> > > From: Simeo Reig [mailto:simreig@terra.es]
> > > Sent: 11 November 2001 22:54
> > > To: Dave Page
> > > Subject: Re: [ODBC] Last inserted id
> > >
> > >
> > > I had think that the problem was this but I believed that was
> > > possible to make a mistake because I'm newer with ADO.
> What must I
> > > do ? I see two possibilities:
> > >
> > >  A) Make a select NEXTVAL from sequence, and
> > >       insert this value in the id
> > >
> > >   B) Insert row and after make a CURRVAL
> > >
> > > What option Do you use ?
> >
> > Use option A), it's multi-user safe whereas the other method isn't.
>
> Unless I'm missing something, option B _is_ multi-user safe.
> currval() doesn't return the "current" value of the sequence
> (like "select * from my_seq" would) -- it returns the last value that
> nextval() gave that session (hence, it isn't defined until
> that session does a nextval()).

The problem is that Microsoft's ActiveX Data Objects (ADO) will not query
the database for additional values in a newly inserted row (in this case,
the id which is inserted as a default by the backend).

I suggest (and use) option A).

As I understand option B), Simeo is proposing to get the current value from
the sequence, insert the complete row client side (so ADO knows the ID),
then set the current value of the sequence (SELECT setval('sequence', 123)).
This is not multiuser safe as a second user may increment the sequence value
in the middle of the first users' 3 queries.

Regards, Dave.

pgsql-odbc by date:

Previous
From: "Geoffrey D. Bennett"
Date:
Subject: Re: Last inserted id
Next
From: David Horwitz
Date:
Subject: Re: Last inserted id