FirebirdSQL logo

CURRENT_TIMESTAMP

Current server date and time in the session time zone, with time zone information

Type

TIMESTAMP WITH TIME ZONE

Caution

Data type changed in Firebird 4.0 from TIMESTAMP WITHOUT TIME ZONE to TIMESTAMP WITH TIME ZONE.Use [fblangref50-contextvars-localtimestamp] to obtain TIMESTAMP WITHOUT TIME ZONE.

Syntax
CURRENT_TIMESTAMP [ (<precision>) ]

<precision> ::= 0 | 1 | 2 | 3

The optional precision argument is not supported in ESQL.

Table 1. CURRENT_TIMESTAMP Parameter
Parameter Description

precision

Precision.The default value is 3.Not supported in ESQL

The default is 3 decimals, i.e. milliseconds precision.

Note
  • The default precision of CURRENT_TIME is 0 decimals, so CURRENT_TIMESTAMP is not the exact sum of CURRENT_DATE and CURRENT_TIME, unless you explicitly specify a precision (i.e. CURRENT_TIME(3) or CURRENT_TIMESTAMP(0)).

  • Within a PSQL module (procedure, trigger or executable block), the value of CURRENT_TIMESTAMP will remain constant every time it is read.If multiple modules call or trigger each other, the value will remain constant throughout the duration of the outermost module.If you need a progressing value in PSQL (e.g. to measure time intervals), use [fblangref50-contextvars-now].

Warning
CURRENT_TIMESTAMP and Firebird Time Zone Support

Firebird 4.0 added support for time zones.As part of this support, an incompatibility with the CURRENT_TIMESTAMP expression was introduced compared to previous versions.

Since Firebird 4.0, CURRENT_TIMESTAMP returns the TIMESTAMP WITH TIME ZONE type.In order for your queries to be compatible with database code of Firebird 4.0 and higher, Firebird 3.0.4 and Firebird 2.5.9 introduced the [fblangref50-contextvars-localtimestamp] expression.In Firebird 3.0.4 and Firebird 2.5.9, LOCALTIMESTAMP is a synonym for CURRENT_TIMESTAMP.

In Firebird 5.0, LOCALTIMESTAMP returns TIMESTAMP [WITHOUT TIME ZONE], while CURRENT_TIMESTAMP returns TIMESTAMP WITH TIME ZONE.

Examples
select current_timestamp from rdb$database
-- returns e.g. 2008-08-13 14:20:19.6170

select current_timestamp(2) from rdb$database
-- returns e.g. 2008-08-13 14:20:23.1200

CURRENT_TRANSACTION

Unique identifier of the current transaction

Type

BIGINT

Syntax
CURRENT_TRANSACTION

The transaction identifier is derived from a counter on the database header page, which is incremented for each new transaction.When a database is restored, this counter is reset to zero.

Examples
select current_transaction from rdb$database

New.Txn_ID = current_transaction;

docnext count = 3

CURRENT_USER

Name of the user of the current connection

Type

VARCHAR(63)

Syntax
CURRENT_USER

CURRENT_USER is equivalent to [fblangref50-contextvars-user].

Example
create trigger bi_customers for customers before insert as
begin
    New.added_by  = CURRENT_USER;
    New.purchases = 0;
end

DELETING

Indicates if the trigger fired for a DELETE operation

Available in

PSQL — DML triggers only

Type

BOOLEAN

Syntax
DELETING

Intended for use in multi-action triggers.

Example
if (deleting) then
begin
  insert into Removed_Cars (id, make, model, removed)
    values (old.id, old.make, old.model, current_timestamp);
end

GDSCODE

Firebird error code of the error in a WHEN …​ DO block

Available in

PSQL

Type

INTEGER

Syntax
GDSCODE

In a “WHEN …​ DO” error handling block, the GDSCODE context variable contains the numeric value of the current Firebird error code.GDSCODE is non-zero in WHEN …​ DO blocks, if the current error has a Firebird error code.Outside error handlers, GDSCODE is always 0.Outside PSQL, it doesn’t exist at all.

Note

After WHEN GDSCODE, you must use symbolic names like grant_obj_notfound etc.But the GDSCODE context variable is an INTEGER.If you want to compare it against a specific error, the numeric value must be used, e.g.335544551 for grant_obj_notfound.

Example
when gdscode grant_obj_notfound, gdscode grant_fld_notfound,
   gdscode grant_nopriv, gdscode grant_nopriv_on_base
do
begin
  execute procedure log_grant_error(gdscode);
  exit;
end