Using sequence name depending on other column

Поиск
Список
Период
Сортировка
От Andrus Moor
Тема Using sequence name depending on other column
Дата
Msg-id d0vlja$1kur$1@news.hub.org
обсуждение исходный текст
Ответы Re: Using sequence name depending on other column
Список 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 по дате отправления: