Re: sequence's plpgsql

From: Richard Huxton <dev(at)archonet(dot)com>
To: Tim McAuley <mcauleyt(at)tcd(dot)ie>, pgsql-general(at)postgresql(dot)org
Subject: Re: sequence's plpgsql
Date: 2003-09-24 17:28:06
Message-ID: 200309241828.06757.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-jdbc

On Wednesday 24 September 2003 17:40, Tim McAuley wrote:
> 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.

You might want to try just using sequences - PG does some caching of generated
values for you. Sorry - can't remember how you alter the cache size, but try
SELECT * FROM my_sequence;
to see the details of its settings.

Use sequences, and from your sequence-holding class do something like:
SELECT nextval('myseq'),nextval('myseq'),...10 times...
That will give you a block of 10 sequence values in one go, and off you go.

If you'd rather have the values in one column, create a single-column table
"seq_count" and populate with values 1..10 then:
SELECT nextval('myseq'),seq_count.id FROM seq_count;

That any use?
--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2003-09-24 17:50:12 Re: About GPL and proprietary software
Previous Message Bruce Momjian 2003-09-24 17:21:50 Re: An idea for IPU ( We need another acronymn! )

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-09-24 17:44:49 Darwin compile flags
Previous Message Bruce Momjian 2003-09-24 17:11:22 Re: NuSphere and PostgreSQL for windows

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2003-09-25 00:08:55 Re: Help: ResultSet..insertRow() not coping with explicit
Previous Message Tim McAuley 2003-09-24 16:40:04 sequence's plpgsql