txid_current_if_assigned()

A function returning the current transaction ID, if assigned
This entry relates to a PostgreSQL feature which is deprecated and may be desupported in future releases.

txid_current_if_assigned() is a system function returning the current transaction ID, if one is assigned.

txid_current_if_assigned() was added in PostgreSQL 8.3.

Usage

txid_current_if_assigned () → bigint

txid_current_if_assigned() returns the current transaction ID as a bigint. Note that a new transaction ID will be not be assigned until a non-read query is made in the current transaction.

This function is deprecated following the introduction of the xid8 data type in PostgreSQL 13 and is superseded by pg_current_xact_id_if_assigned().

Change history

Examples

Basic usage example for txid_current_if_assigned() - a transaction will not have a transaction ID until it makes a change to the database:

postgres=# BEGIN;
BEGIN

postgres=*# SELECT txid_current_if_assigned();
 txid_current_if_assigned 
--------------------------
                         
(1 row)

postgres=*# SELECT 1;
 ?column? 
----------
        1
(1 row)

postgres=*# SELECT txid_current_if_assigned();
 txid_current_if_assigned 
--------------------------
                         
(1 row)

Time: 0.986 ms
postgres=*# INSERT INTO foo VALUES (1);
INSERT 0 1

postgres=*# SELECT txid_current_if_assigned();
 txid_current_if_assigned 
--------------------------
                      742
(1 row)

Categories

Deprecated, System function, Transactions

See also

pg_current_xact_id_if_assigned(), txid_current()