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

Re: [INTERFACES] locking on database updates

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: "'Pgsql Interfaces'" <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: [INTERFACES] locking on database updates
Date: 1999-12-07 17:12:34
Message-ID: 19991207111234.A6021@rice.edu (view raw or flat)
Thread:
Lists: pgsql-interfaces
On Tue, Dec 07, 1999 at 04:34:37PM -0000, Gary Stainburn wrote:
> 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?

create table foo (bar serial, baz text);
insert into foo (baz) values ('wooble');
select currval('foo_bar_seq');

> 
> Thanks,
> 
> Gary

you're welcome ;-)

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005

In response to

pgsql-interfaces by date

Next:From: Nicolas HuillardDate: 1999-12-07 17:26:41
Subject: RE: [INTERFACES] locking on database updates
Previous:From: Paul S. GanneyDate: 1999-12-07 16:46:30
Subject: Deleting duplicate records

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