HSQLDB CREATE TRIGGER throws exception: wrong or missing data impact clause in declaration: MODIFIES SQL

StackOverflow https://stackoverflow.com/questions/21753266

  •  11-10-2022
  •  | 
  •  

Question

I want to create a trigger for a table that inserts a row into another table whenever a new row is inserted.

CREATE TABLE S.A (
    ID NUMERIC(18) NOT NULL,
    OTHERID NUMERIC(18) NOT NULL,
);

CREATE TABLE S.B
(
    ...
    AID NUMERIC(18) NOT NULL,
    ...
);

CREATE TRIGGER mytrigger BEFORE INSERT ON S.B
     REFERENCING NEW AS newrow FOR EACH ROW
     INSERT INTO S.A (ID, OTHERID) VALUES (newrow.AID, newrow.AID);

However I get an exception with the trigger statement:

Caused by: org.hsqldb.HsqlException: wrong or missing data impact clause in declaration: MODIFIES SQL
    at org.hsqldb.error.Error.error(Unknown Source)
    ...

The documentation says nothing about having to use MODIFIES SQL in this statement. Can anyone tell me how to correctly write this trigger?

Was it helpful?

Solution

I think this is relevant, from here

BEFORE triggers cannot modify the other tables of the database. All BEFORE triggers can veto the action by throwing an exception.

whereas

AFTER triggers can also perform additional data changes, for example inserting an additional row into a different table for data audits.

i.e. you will need to change your strategy to an AFTER or an INSTEAD OF trigger if you are to insert into another table.

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