Using sequence name depending on other column

From: "Andrus Moor" <eetasoft(at)online(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: Using sequence name depending on other column
Date: 2005-03-12 21:05:41
Message-ID: d0vlja$1kur$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vitaly Belman 2005-03-12 21:44:38 Moving an object (function/table, etc) from schema to schema
Previous Message Michael Ben-Nes 2005-03-12 20:39:05 Log each DB to a diffrent file