Return the timestamp captured at the start of the current transaction.
TRANSACTION_TIMESTAMP()
## Overview Returns the current date and time (with time zone) captured at the start of the current transaction. The value is identical to NOW() and CURRENT_TIMESTAMP(); the three names are interchangeable. Use TRANSACTION_TIMESTAMP when the code is explicitly reasoning about transaction boundaries (for example in an audit layer that distinguishes transaction-level from statement-level or per-call time readings). ## Behavior - Returns a TIMESTAMP WITH TIME ZONE value. - Never returns NULL. - Stable within a transaction; every reference returns the same instant. - Functionally identical to NOW() and CURRENT_TIMESTAMP(). - Distinct from STATEMENT_TIMESTAMP (fresh per statement) and CLOCK_TIMESTAMP (fresh per call). - Requires the function-call parentheses. ## Timezone handling - Carries the session time zone offset. - Use AT TIME ZONE to convert to a specific zone, for example TRANSACTION_TIMESTAMP() AT TIME ZONE 'UTC'. ## Compatibility - Extension to the SQL standard. For portable SQL prefer CURRENT_TIMESTAMP. Use TRANSACTION_TIMESTAMP only when the explicit transaction-scope naming improves code clarity.
-- Transaction start timestamp
SELECT TRANSACTION_TIMESTAMP();
-- Compare transaction, statement, and wall-clock timestamps
SELECT TRANSACTION_TIMESTAMP() AS txn_ts,
STATEMENT_TIMESTAMP() AS stmt_ts,
CLOCK_TIMESTAMP() AS clock_ts;
-- Verify equivalence with NOW
SELECT TRANSACTION_TIMESTAMP() = NOW() AS are_equal;
-- Stamp every row written in a transaction with the same instant
INSERT INTO security.audit.access_log (action, occurred_at)
SELECT action, TRANSACTION_TIMESTAMP()
FROM staging.logs.pending_actions;
-- Window queries relative to transaction start
SELECT COUNT(*) AS rows_after_txn_start
FROM analytics.events.user_activity
WHERE occurred_at >= TRANSACTION_TIMESTAMP() - INTERVAL '1 hour';