Subject Re: [firebird-support] Re: Problem with trigger - too many concurrent executions
Author Helen Borrie
At 03:10 PM 7/12/2005 +0000, Svein Erling Tysvær wrote:
>Hi Peter!
>
>AFTER INSERT should be used for updating other tables, you want to do
>something like:
>
>CREATE TRIGGER "INPT_lmd" FOR INPT ACTIVE
>BEFORE INSERT OR UPDATE POSITION 1
>AS
>BEGIN
> NEW.LMD='now';
>END

For Firebird, if you use the 'now' context variable, it needs to cast to
timestamp in most conditions:

CREATE TRIGGER "INPT_lmd" FOR INPT ACTIVE
BEFORE INSERT OR UPDATE POSITION 1
AS
BEGIN
NEW.LMD=CAST('now' AS TIMESTAMP);
END

You also have this option:

NEW.LMD=CURRENT_TIMESTAMP;

Where this context variable differs from 'now' is that CURRENT_TIMESTAMP
will record the same time for every row encompassed by a single statement,
whereas 'now' records the exact server time when the statement instance is
posted.

In case that is not quite clear, take a statement like this:

update atable
set somedata = 'something'
where <some criterion applying to several rows>

With current_timestamp, each affected row will get the same
timestamp; with cast('now'...) each row gets the latest timestamp as the
row is posted. Since both CURRENT_TIMESTAMP and 'now' return the time part
to the last whole second (.0000 in the subsecond part) an operation using
'now' might well return identical timestamps for all rows. I'm mentioning
this just in case you were ever tempted to use a system timestamp as a
primary or unique key. :-))

./heLen