PostgreSQL pg_trigger_depth() Function

The PostgreSQL pg_trigger_depth() function returns the current nesting level of triggers.

pg_trigger_depth() Syntax

Here is the syntax of the PostgreSQL pg_trigger_depth() function:

pg_trigger_depth() -> integer

Parameters

The PostgreSQL pg_trigger_depth() function does not require any parameters.

Return value

The PostgreSQL pg_trigger_depth() function returns the current nesting level of triggers. The pg_trigger_depth() function will returns 0 if it isn’t called inside a trigger.

pg_trigger_depth() Examples

To get the current trigger’s nesting level, use the following statement with the pg_trigger_depth() function:

SELECT pg_trigger_depth();
 pg_trigger_depth
------------------
                0

You should call the pg_trigger_depth() function inside a trigger, otherwise it returns 0.