Re: Auto increment/sequence on multiple columns?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Nick <nboutelier(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto increment/sequence on multiple columns?
Date: 2004-09-15 16:13:59
Message-ID: 20040915161359.GA26804@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Sep 12, 2004 at 09:16:37 -0700,
Nick <nboutelier(at)hotmail(dot)com> wrote:
> This is actually a table that holds message threads for message
> boards. Column A is really 'message_board_id' and column B is
> 'thread_id'. I would like every new thread for a message board to have
> a 'thread_id' of 1 and increment from there on. -Nick

Since thread ids should be opaque just use one sequence that generates
all thread ids rather than having separate thread id sets for each message
board id.

If you really want to have thread ids start at 1 and increase by 1 for
each new thread per message boad, sequences aren't the right tool.
The simplest way to do this is when adding a new thread to lock the
table against concurrent updates and then use a new thread id that
is one higher than the current highest for the message board of interest.
This doesn't handle what to do if you need to delete a thread.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Atkins 2004-09-15 16:29:13 Converting varchar() to text
Previous Message Jeffrey W. Baker 2004-09-15 16:11:37 Re: disk performance benchmarks