Stream triggers row functions
=============================

bdr.trigger_get_row
^^^^^^^^^^^^^^^^^^^

This function returns the contents of a trigger row specified by an
identifier as a ``RECORD`` . This function returns ``NULL`` if called
inappropriately, that is, called with ``SOURCE_NEW`` when the operation
type (TG_OP) is ``DELETE`` .

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_row(row_id text)

Parameters
^^^^^^^^^^

- ``row_id`` — Identifier of the row. Can be any of ``SOURCE_NEW`` ,
  ``SOURCE_OLD`` , and ``TARGET`` , depending on the trigger type and
  operation. (See the descriptions of the individual trigger types.)

bdr.trigger_get_committs
^^^^^^^^^^^^^^^^^^^^^^^^

This function returns the commit timestamp of a trigger row specified by
an identifier. If not available because a row is frozen or isn’t
available, returns ``NULL`` . Always returns ``NULL`` for row identifier
``SOURCE_OLD`` .

.. _synopsis-1:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_committs(row_id text)

.. _parameters-1:

Parameters
^^^^^^^^^^

- ``row_id`` — Identifier of the row. Can be any of ``SOURCE_NEW`` ,
  ``SOURCE_OLD`` , and ``TARGET`` , depending on trigger type and
  operation. (See the descriptions of the individual trigger types.)

bdr.trigger_get_xid
^^^^^^^^^^^^^^^^^^^

This function returns the local transaction id of a TARGET row specified
by an identifier. If not available because a row is frozen or isn’t
available, returns ``NULL`` . Always returns ``NULL`` for ``SOURCE_OLD``
and ``SOURCE_NEW`` row identifiers.

Available only for conflict triggers.

.. _synopsis-2:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_xid(row_id text)

.. _parameters-2:

Parameters
^^^^^^^^^^

- ``row_id`` — Identifier of the row. Can be any of ``SOURCE_NEW`` ,
  ``SOURCE_OLD`` , and ``TARGET`` , depending on trigger type and
  operation. (See the descriptions of the individual trigger types.)

bdr.trigger_get_type
^^^^^^^^^^^^^^^^^^^^

This function returns the current trigger type, which can be
``CONFLICT`` or ``TRANSFORM`` . Returns null if called outside a stream
trigger.

.. _synopsis-3:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_type()

bdr.trigger_get_conflict_type
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This function returns the current conflict type if called inside a
conflict trigger. Otherwise, returns ``NULL`` .

See :ref:`Types of Conflict <Types of Conflict>` 

for possible return values of this function.

.. _synopsis-4:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_conflict_type()

bdr.trigger_get_origin_node_id
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This function returns the node id corresponding to the origin for the
trigger row_id passed in as argument. If the origin isn’t valid (which
means the row originated locally), returns the node id of the source or
target node, depending on the trigger row argument. Always returns
``NULL`` for row identifier ``SOURCE_OLD`` . You can use this function
to define conflict triggers to always favor a trusted source node.

.. _synopsis-5:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.trigger_get_origin_node_id(row_id text)

.. _parameters-3:

Parameters
^^^^^^^^^^

- ``row_id`` — Identifier of the row. Can be any of ``SOURCE_NEW`` ,
  ``SOURCE_OLD`` , and ``TARGET`` , depending on trigger type and
  operation. (See the descriptions of the individual trigger types.)

bdr.ri_fkey_on_del_trigger
^^^^^^^^^^^^^^^^^^^^^^^^^^

When called as a BEFORE trigger, this function uses FOREIGN KEY
information to avoid FK anomalies.

.. _synopsis-6:

Synopsis
^^^^^^^^

.. code:: sql

   bdr.ri_fkey_on_del_trigger()
