Are PostgreSQL functions transactional?

前端 未结 4 2081
面向向阳花
面向向阳花 2020-12-02 17:57

Is a PostgreSQL function such as the following automatically transactional?

CREATE OR REPLACE FUNCTION refresh_materialized_view(name)
  RETURNS integer AS
$         


        
4条回答
  •  萌比男神i
    2020-12-02 18:53

    In the function level, it is not transnational. In other words, each statement in the function belongs to a single transaction, which is the default db auto commit value. Auto commit is true by default. But anyway, you have to call the function using

    select schemaName.functionName()

    The above statement 'select schemaName.functionName()' is a single transaction, let's name the transaction T1, and so the all the statements in the function belong to the transaction T1. In this way, the function is in a single transaction.

提交回复
热议问题