Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top