This column cannot be updated because it is derived from an SQL function or expression. Attempted update of read-only column.
This error message might show up when you try to update a computed column. Since such column is computed, you cannot write values directly into it. If you really need a specific value, you need to change the computed source.
This error message also shows up when you try to change values of NEW and OLD variables in triggers when it doesn't make sense. The problem is evident in Firebird 2.0 and higher, while the previous versions silently ignored such logical errors.
Examples include updating OLD.something variable in INSERT triggers, or NEW.something in DELETE triggers. You might have multi-action trigger, in which case you need to check the context variables: DELETING and INSERTING to find out which operation caused the trigger to fire.
CREATE TRIGGER ...
ACTIVE BEFORE INSERT OR UPDATE OR DELETE ...
if (inserting) then new.something = 10;
if (deleting and old.something = 10) then ...
It also happens when you try to alter NEW.something values in AFTER trigger. There is no sense trying to change NEW. variable AFTER the INSERT or UPDATE operation has been completed, since values we're already written to the database. Here's an example of code that works in Firebird 1.5, but does not work properly:
CREATE TABLE t1 ( c1 integer );
CREATE TRIGGER tr1 FOR t1
ACTIVE AFTER INSERT POSITION 0
new.c1 = 10;
Now, if you try to insert into table T1:
INSERT INTO T1 (C1) VALUES (5);
You will end up with value 5 in the table. The reason is that trigger TR1 is AFTER insert trigger, so it will change value of variable new.c1 AFTER the insert operation is completed.
To protect you from such logic error, Firebird 2.0 prevents declaring such constructs in the first place.
This error can also show up if you try to declare a DEFAULT column value on a COMPUTED column. To fix it, simply drop the column and create it again.