Subject | Re: [firebird-support] What makes a column read only? |
---|---|
Author | Thomas Steinmaurer |
Post date | 2012-11-05T18:51:15Z |
> I have this table definition:You can't set a new column value in an AFTER trigger. Use a BEFORE trigger.
> CREATE TABLE CONSUMPTION
> (
> ID KEYS NOT NULL,
> QUANTITY Integer DEFAULT 0,
> UNITPRICE Numeric(18,2) DEFAULT 0,
> CONSUMEDVALUE Numeric(18,2) DEFAULT 0,
> REMARKS Varchar(50) COLLATE UNICODE_CI_AI,
> CONSUMED Timestamp,
> MATURITYFIRST Integer,
> MATURITYBEST Integer,
> MATURITYPAST Integer,
> TRANSFER_ID Bigint,
> FK_CBBOTTLEID Bigint,
> FK_CELLARBOOK_ID KEYS,
> FK_RATING_ID KEYS,
> FK_CELLAR_ID KEYS,
> FK_REASON_ID KEYS,
> CREATED_AT Timestamp,
> UPDATED_AT Timestamp,
> CREATED_BY KEYS,
> UPDATED_BY KEYS,
> CONSTRAINT PK_CONSUMPTION PRIMARY KEY (ID)
> )
>
> CREATE TRIGGER CONSUMPTION_CONSVAL FOR CONSUMPTION
> ACTIVE AFTER INSERT OR UPDATE POSITION 0
> AS
> BEGIN
> /* enter trigger code here */
> new.CONSUMEDVALUE = new.UNITPRICE * new.QUANTITY;
> END
>
> When I try to update manually (e.g. using FlameRobin or IBExpert) the
> column "CONSUMEDVALUE" or when I try to create the above trigger I get
> this error:
>
> SQL Message : -151
> This column cannot be updated because it is derived from an SQL function
> or expression.
>
> Engine Code : 335544359
> Engine Message :
> attempted update of read-only column
>
> What am I doing wrong?
--
With regards,
Thomas Steinmaurer
http://www.upscene.com/