0

I have the following sql migration, that doesn't work with h2. If I remove the following SQL - everything works fine. How can i solve it?

SQL State  : 42001
Error Code : 42001
Message    : Syntax error in SQL statement "CREATE TABLE USER_AUTHORITY
(
    USER_AUTHORITY_ID  BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    USER_ID            BIGINT REFERENCES USR (USER_ID)            NOT NULL[*],
    AUTHORITY_ID       BIGINT REFERENCES AUTHORITY (AUTHORITY_ID) NOT NULL,
    OPERATION          VARCHAR(2)                                 NOT NULL,
    CREATION_DATETIME  TIMESTAMP WITH TIME ZONE                   NOT NULL,
    MODIFYING_DATETIME TIMESTAMP WITH TIME ZONE                   NOT NULL
)"; expected "DEFERRABLE";
Location   : db/migration/V1__Schema.sql (/home/v/IdeaProjects/stocky/user-service/build/resources/main/db/migration/V1__Schema.sql)
Line       : 29
Statement  : create table user_authority

1 Answers1

1

This is a bug of the parser. I filled a new issue about it: https://github.com/h2database/h2database/issues/3413

You can specify NOT NULL before REFERENCES as a workaround.

USER_ID BIGINT NOT NULL REFERENCES USR (USER_ID),
AUTHORITY_ID BIGINT NOT NULL REFERENCES AUTHORITY (AUTHORITY_ID),
Evgenij Ryazanov
  • 6,960
  • 2
  • 10
  • 18