RE: JDBC problem - Mailing list pgsql-interfaces

From Peter Mount
Subject RE: JDBC problem
Date
Msg-id 1B3D5E532D18D311861A00600865478CF1B2DC@exchange1.nt.maidstone.gov.uk
Whole thread Raw
In response to JDBC problem  (BogdanKRomski <b.kromski@gaschka.pl>)
List 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@it.maidstone.gov.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@visionforisrael.com]
Sent: Friday, August 25, 2000 9:50 AM
To: John McKown
Cc: BogdanKRomski; pgsql-interfaces@postgresql.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



pgsql-interfaces by date:

Previous
From: Cedar Cox
Date:
Subject: Re: JDBC problem
Next
From: "amish seth"
Date:
Subject: Solaris Platform support!