Re: Roll Back dont roll back counters

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: "Roderick A(dot) Anderson" <raanders(at)tincan(dot)org>, Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Ben-Nes Michael <miki(at)canaan(dot)co(dot)il>, pgsql-general(at)postgresql(dot)org
Subject: Re: Roll Back dont roll back counters
Date: 2001-08-16 13:39:31
Message-ID: 20010816133931.99789.qmail@web10005.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


--- "Roderick A. Anderson" <raanders(at)tincan(dot)org>
wrote:
> On Thu, 16 Aug 2001, Martijn van Oosterhout wrote:
>
> > Why do people care about holes anyway? I've never
> understood that...
>
> The single seat syndrome? (It's my database and I'm
> the only one using
> it.)

If this is the case then simply use the setval
command, insert with an explicit value in the serial
column, or better yet, don't rollback or abort
transactions :).

> Trying to put intelligence into the field? (I can
> tell the order the
> entries were made in the table using this field.)

You can tell the order the entries were made whether
or not their are "holes" in your sequence. No matter
how many aborted transactions you might have had the
bigger sequence numbers were inserted last :). A
simple "SELECT * FROM my_table ORDER BY
my_serial_field" will happily sort your table
chronologically.

On the other hand, you could probably use a
combination of explicit locks a non-SERIAL integer
primary key, and a select statement like "SELECT
my_primary_key FROM my_table ORDER BY my_primary_key
DESC LIMIT 1" to fetch your current highest primary
key value. You could then add one to this number on
your insert. It would serialize inserts to your table
(not a big deal if you are the only one using it), and
it would require more work (and more discipline) when
programming, but you wouldn't get any holes.

Good Luck,
Jason

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message news 2001-08-16 14:09:12 What's up with FTP?
Previous Message Bruce Momjian 2001-08-16 13:33:16 Re: PostgreSQL buffer exploits