pg_transaction_status

pg_transaction_status — Get the current in-transaction status

Synopsis

pg_transaction_status conn

Description

pg_transaction_status returns the current status of the connection: whether it is inside a transaction block, outside a transaction block, or inside a failed transaction block. A transaction block begins with the SQL command BEGIN, and ends with one of the SQL commands COMMIT or ROLLBACK. A failed transaction block is a transaction block after any error occurs; PostgreSQL will ignore all SQL commands until the end of the transaction block. pg_transaction_status allows an application to determine if it is in a transaction block or failed transaction block.

Arguments

conn

The handle of the connection on which to report transaction status.

Return Value

One of the string values in the following table:

ValueDescription
IDLEConnection is idle, not in a transaction block.
INTRANSConnection is in a (non-failed) transaction block.
INERRORConnection is in a failed transaction block.
UNKNOWNConnection is bad or in an unknown state.

Notes

This command uses or emulates the PostgreSQL libpq function PQtransactionStatus.