Re: Using sequence name depending on other column

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Andrus Moor <eetasoft(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using sequence name depending on other column
Date: 2005-03-13 03:59:58
Message-ID: 20050313035958.GA28240@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Mar 12, 2005 at 23:05:41 +0200,
Andrus Moor <eetasoft(at)online(dot)ee> wrote:
> I have table containing different types of documents (type A, B and C).
>
> Each document type must have separate sequential ID starting at 1
>
> ID of first inserted record of type A must be set to 1
> ID of first inserted record of type B must be also set to 1
> ID of second record of type A must be set to 2
> etc.

Sequences aren't designed for doing this. If you aren't doing lots of
updates, just lock the table and assign the next id as the current max id
of that type + 1.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-03-13 04:35:51 Re: partitionning
Previous Message Lonni J Friedman 2005-03-13 02:19:51 Re: postgresql error