Subject Re: [ib-support] Updating a timestamp field
Author Helen Borrie
At 12:35 PM 31-10-02 +0000, you wrote:
>I have a table with two timestamps
>
> TIMESTAMP_ADDED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
> TIMESTAMP_SENT TIMESTAMP
>
>When I update the TIMESTAMP_SENT field, I'd like to use the time on
>the server, rather than passing in the (possibly incorrect)client's
>time/date.
>
>Can I do something like this:
>
>UPDATE myTable(TIMESTAMP_SENT)
>VALUES( NOW() )
>
>or, would I have to do this as a SP in order to get the server time?

If you want to use the timestamp literal 'NOW' you must include it in
single quotes and (in Dialect 3) cast it explicitly. The SQL-compliant
server context variable CURRENT_TIMESTAMP might be simpler. They are
interchangeable.

Here are the two syntaxes (used in triggers, which is the common way to
timestamp inserts and updates):

create trigger bu_mytable
active before update position 0
as
begin
new.TIMESTAMP_SENT = CURRENT_TIMESTAMP;
end

create trigger bi_mytable
active before insert position 0
as
begin
new.TIMESTAMP_ADDED = cast('Now' as TIMESTAMP);
end

heLen