RE: JDBC problem

From: Peter Mount <PeterM(at)maidstone(dot)gov(dot)uk>
To: "'Cedar Cox'" <cedarc(at)visionforisrael(dot)com>, John McKown <jmckown(at)prodigy(dot)net>
Cc: BogdanKRomski <b(dot)kromski(at)gaschka(dot)pl>, pgsql-interfaces(at)postgresql(dot)org
Subject: RE: JDBC problem
Date: 2000-08-25 11:21:17
Message-ID: 1B3D5E532D18D311861A00600865478CF1B2DC@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Serial actually allocates numbers in blocks (default=1), so you won't get a
duplicate.

The plus side of this is that you can set the block size >1, so if you are
loading lots of data, you can set it to 10, then it only allocates a new
block once the last one is used up. However, if your connection is closed
before the block is used, the unused numbers are lost.

Peter

PS: Major email problems here at mbc, so I may not be able to reply to any
directly written replies for a while (I accidentally erased all the
addresses, whoops)...

--
Peter Mount
Enterprise Support Officer, Maidstone Borough Council
Email: petermount(at)it(dot)maidstone(dot)gov(dot)uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council

-----Original Message-----
From: Cedar Cox [mailto:cedarc(at)visionforisrael(dot)com]
Sent: Friday, August 25, 2000 9:50 AM
To: John McKown
Cc: BogdanKRomski; pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] JDBC problem

On Thu, 24 Aug 2000, John McKown wrote:

> The syntax that I've seen is:
>
> insert into KEY_ITEM (key_item_id,keyname) values
> (select max(key_item_id)+1,'?' FROM KEY_ITEM);
>
> Just out of curiousity, why not make key_item_id a SERIAL field? That way,
> if you don't specify a value, it gets the next value from the associated
> sequence.

I was going to ask you to explain SERIAL but the documentation makes it
fairly clear.. basically just the next value, yes? Simply setting the
field type to SERIAL seems to be the same as the MS Access 'autonumber'
field. Is this correct?

One detail that seems to have an advantage over the MAX+1 method is that
in the case of adding a new record, deleting it, then adding another new
record the ID will not be reused (correct?).

Question: What happens when transactions enter the picture? Will you get
duplicate values, or holes, or does it work just fine?

-Cedar

Browse pgsql-interfaces by date

  From Date Subject
Next Message Charles Killmer 2000-08-25 13:46:00 Access and PsqLODBC
Previous Message Phil Davey 2000-08-25 10:43:34 Access 2000 and PostgreSQL 6.5