sequence's plpgsql

From: Tim McAuley <mcauleyt(at)tcd(dot)ie>
To: pgsql-general(at)postgresql(dot)org
Subject: sequence's plpgsql
Date: 2003-09-24 16:40:04
Message-ID: 3F71C8E4.1070309@tcd.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-jdbc

Hi,

I've hit a little problem and was wondering if anyone might be able to
give some help.

Set-up:

- JBoss appserver using entity beans to access database
- Using sequence pattern to update primary keys for several tables.
Basically it is a method of getting primary keys without hitting the
database. It actually hits the database every 10th go and updates the
counter by 10 in the database.

(now the bold bit)
- We have a stored procedure that actually updates one of the sequences
as well. It increments one at a time using this code:

SELECT INTO NewPK pkIndex FROM PrimaryKeyGenerator WHERE Name =
SequenceName FOR UPDATE;
UPDATE PrimaryKeyGenerator SET pkIndex = NewPK + 1 WHERE Name =
SequenceName;

I believe the "FOR UPDATE" won't actually do any good inside a plpgsql
call. Am I right?

Problem:

I have just called this stored procedure from outside the system using
10 threads and have got some errors due to duplicate entries on the
unique index. If it was only the stored procedures using this pk
generator then I could use a postgresql sequence but it isn't. If the
entity beans were to use the sequence, they'd have to make a database
call every time.

Any thoughts?

I'm thinking I may need to switch to using a sequence because the entity
beans don't actually update this particular table very often but would
prefer not to for portability reasons.

Thanks,

Tim

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Bartlett 2003-09-24 16:42:00 Re: career in SQL/Database administration
Previous Message btober 2003-09-24 16:29:49 Re: career in SQL/Database administration

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2003-09-24 16:47:15 Re: [GENERAL] pgindented tsearch2 for 7.3.4
Previous Message Greg Stark 2003-09-24 16:39:53 Re: pg_dump doesn't dump binary compatible casts

Browse pgsql-jdbc by date

  From Date Subject
Next Message Richard Huxton 2003-09-24 17:28:06 Re: sequence's plpgsql
Previous Message Jim Wright 2003-09-24 13:50:53 Re: Help: ResultSet..insertRow() not coping with explicit