Re: Using sequence name depending on other column - Mailing list pgsql-general

From Andrus
Subject Re: Using sequence name depending on other column
Date
Msg-id d16ekr$2o4q$1@news.hub.org
Whole thread Raw
In response to Using sequence name depending on other column  ("Andrus Moor" <eetasoft@online.ee>)
Responses Re: Using sequence name depending on other column  (Russell Smith <mr-russ@pws.com.au>)
List pgsql-general
>> > 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.
>>
> If you are happy with the fact that a sequence may leave a whole in
> the numbers.  You are probably best to no set a default value for an
> integer, or big integer.  Then run a before trigger for each row.  That
> trigger will assign a value to the column based on the value given for
> the type.

Russell,

thank you.
I'm a new to Postgres.
Is there any sample how to write such trigger ?

Before inserting each row it should set document id from sequence
corresponding to insertable document type.

Andrus.



pgsql-general by date:

Previous
From: Harald Fuchs
Date:
Subject: Re: prelimiary performance comparison pgsql vs mysql
Next
From: peter Willis
Date:
Subject: Re: Question about accessing current row data inside trigger