Skip site navigation (1) Skip section navigation (2)

RE: [INTERFACES] locking on database updates

From: Nicolas Huillard <nhuillard(at)ghs(dot)fr>
To: "'Gary Stainburn'" <gary(dot)stainburn(at)ringways(dot)co(dot)uk>, "'Pgsql Interfaces'" <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: RE: [INTERFACES] locking on database updates
Date: 1999-12-07 17:26:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
This sounds like a question posted a few months ago (sept/oct 99) in this list. Look at the archive, I'm sure you'll have an positive answer (AFAIR) on that point.

Nicolas Huillard

-----Message d'origine-----
De:	Gary Stainburn [SMTP:gary(dot)stainburn(at)ringways(dot)co(dot)uk]
Date:	mardi 7 décembre 1999 17:35
À:	'Pgsql Interfaces'
Objet:	RE: [INTERFACES] locking on database updates

Hi all,

I've just read the last message I sent and apologise for the poor English.
Let me put it a little clearer.

I agree that using a type 'serial' will give me what I want 
regarding the key field for my table, and gets round the problem
of concurrent users trying to create records with the same number.

The problem is that this does not actually give me the number that
was just created.  As there is no guarantee that the other fields in
the table are unique (hence the serial field in the first place) I cannot
simply do a select to retrieve it.

Has anyone any ideas?


-----Original Message-----
From:	Gary Stainburn [SMTP:gary(dot)stainburn(at)ringways(dot)co(dot)uk]
Sent:	Tuesday, December 07, 1999 12:21 PM
To:	'dougt(at)mugc(dot)cc(dot)monash(dot)edu(dot)au'
Cc:	'Pgsql Interfaces'
Subject:	RE: [INTERFACES] locking on database updates

-----Original Message-----
From:	Douglas Thomson [SMTP:dougt(at)mugc(dot)cc(dot)monash(dot)edu(dot)au]
Sent:	Tuesday, December 07, 1999 11:16 AM
To:	Gary Stainburn
Subject:	Re: [INTERFACES] locking on database updates

!> Is there any way to easily retrieve the sequence number just created =
!> without having the same contension problems I originally wanted to =
!> avoid?
!Do you need to find out the next value that will be used before you
!use it? If so there may be a problem...
!However, if you only need to do inserts and find out afterwards what
!sequence number got used then there is no problem. Postgres looks
!after making sure multiple simultaneous backend processes don't
!duplicate sequence numbers. I think it actually reserves a few
!numbers in the sequence for each process, so it is possible to get
!small gaps in the sequence, or for the sequence numbers to be not
!strictly chronological...
!As for the how - well, I simply selected back the row I had just
!inserted to extract the sequence number column :-)

It's not important that I know the number beforehand.  However, as 
this is the only field that is guaranteed to be unique, getting the 
sequence number using  a select statement may not work.
It doesn't matter
Gary Stainburn.
Work: gary(dot)stainburn(at)ringways(dot)co(dot)uk
REVCOM: gary(dot)stainburn(at)revcom(dot)org(dot)uk
The nice thing about standards is that there are so many of them to choose from. -- Andrew S. Tanenbaum


pgsql-interfaces by date

Next:From: Tom LaneDate: 1999-12-07 17:45:35
Subject: Re: [INTERFACES] locking on database updates
Previous:From: Ross J. ReedstromDate: 1999-12-07 17:12:34
Subject: Re: [INTERFACES] locking on database updates

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group