TXID_CURRENT

Return the identifier of the current transaction.

Category: miscReturns: BIGINTDialect: PostgreSql

Syntax

TXID_CURRENT()

Description

## Overview Returns the identifier of the current transaction as a 64-bit integer. Use this function for audit logging, correlating multiple statements that share a transaction, or detecting whether a block of code runs inside a single transaction. ## Session context - The value is stable for the duration of a single transaction. - Each new transaction receives a fresh id. - Takes no arguments. - Never returns NULL. ## Behavior - Returns a BIGINT transaction id. - Deterministic within a single transaction. - Side effect free. ## Compatibility - PG-compat alias for `txid_current` function.

Examples

-- Read the current transaction id
SELECT TXID_CURRENT();
-- Stamp an audit record with the transaction id
INSERT INTO ops.audit.events (event_id, tx_id, actor, occurred_at)
VALUES (UUID(), TXID_CURRENT(), CURRENT_USER(), CURRENT_TIMESTAMP);
-- Verify that two statements share a transaction
BEGIN;
  SELECT TXID_CURRENT() AS tx_before;
  -- ... work ...
  SELECT TXID_CURRENT() AS tx_after;  -- same value as tx_before
COMMIT;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →