简体   繁体   中英

HSQLDB - link several sequences for several columns of the table

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM