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

From Andrus Moor
Subject Using sequence name depending on other column
Date
Msg-id d0vlja$1kur$1@news.hub.org
Whole thread Raw
Responses Re: Using sequence name depending on other column  (Bruno Wolff III <bruno@wolff.to>)
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.


I tried to implement this as

CREATE SEQUENCE a_id_seq;
CREATE SEQUENCE b_id_seq;
CREATE SEQUENCE c_id_seq;

CREATE TABLE documents (
  doctype CHAR(1),
  id NUMERIC DEFAULT nextval(doctype ||'_dokumnr_seq'),
  documentcontents TEXT );


but got an error

ERROR:  cannot use column references in default expression

Any idea how to implement this ?

Andrus.



pgsql-general by date:

Previous
From: Mike Rylander
Date:
Subject: Re: partitionning
Next
From: Michael Ben-Nes
Date:
Subject: Log each DB to a diffrent file