문제

I would like to link several sequences for generating default values for several columns of a table.

For example:

CREATE SEQUENCE seq1 START WITH 1;
CREATE SEQUENCE seq2 START WITH 1;
CREATE TABLE mytable (rid int GENERATED BY DEFAULT AS SEQUENCE seq1 PRIMARY KEY, p63 int GENERATED BY DEFAULT AS SEQUENCE seq2)

Unfortunately, an error is occured: "identity definition not allowed"

In Postgresql is working.

Any idea ?

Thanks

도움이 되었습니까?

해결책

The first use of the sequence is allowed. You can write a BEFORE INSERT TRIGGER to insert sequence values into the second column.

다른 팁

Having the same issue, I came upon this post. I used another workaround :

CREATE SEQUENCE seq1 START WITH 1;
CREATE SEQUENCE seq2 START WITH 1;

CREATE TABLE mytable (
    rid int DEFAULT nextval('seq1') NOT NULL,
    p63 int NOT NULL
);

ALTER TABLE mytable ALTER p63 SET DEFAULT NEXTVAL('seq2');

Altering the p63 column after table creation made possible to use the seq2 sequence while it was not accepted when creating the table.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top