For example:
create table test (id numeric, t date not null);
create trigger test_in
before insert on test
for each row
when New.t is null
begin
-- set New.t = now();
end;
Set New.t didn’t work, where can be only select/insert/update/delete stmt.
I can not change the database structure (can set default value).
After insert trigger also not suitable because of “not null” constrain.
The only solution I’ve found:
insert into test values (New.id, now());
select raise(ignore);
test database for illustrative purposes only, in practice there are more complicated cases with calculated data. There may be something like this “update New set New.t = now()”, or not?
No, you can’t update NEW.
What I tend to do is use a VIEW with an INSTEAD OF trigger as mu is too short commented above.
In your case the best solution may be to use an AFTER INSERT/UPDATE trigger WHEN NEW.t IS NULL to update t in the affected row(s):
FYI, your
idcolumn should probably be declared as INTEGER PRIMARY KEY…