> From: "António Vieira (DSI)" <[EMAIL PROTECTED]>

> My question is if it's possible to change the value inserted or updated
> inside a trigger?
>
> Something like this:
> CREATE TABLE foo (a);
> BEFORE INSERT ON foo BEGIN
>     NEW.a=1;
> END;
>
> I know that by the specification it's not possible to do this, and by my
> tests isn't possible to, but maybe someone know a valid 'insert-statement'
> or 'select-statement' that do what I need, or someone else that know
sqlite
> so well that tell me that is not possible.
>
> Is it very important to me be sure if it is possible or not, because if
> isn't possible it will represents a lot of work out side DB.

António,

It isn't possible to modify the special NEW or OLD records in a trigger. But
you don't need to do that to accomplish your goal. Rather than changing the
NEW value before it is inserted into the table, you need to change the value
in the table after it is inserted. This can be done in an AFTER trigger as
shown below.


CREATE TABLE foo (a);

CREATE TRIGGER in_foo
AFTER INSERT ON foo BEGIN
    UPDATE foo SET a = 1 WHERE rowid = last_insert_rowid();
END;

INSERT INTO foo VALUES(2);

SELECT * FROM foo;
a
----
1

I hope this helps.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to