Re: stable for each row before insert trigger - Mailing list pgsql-general

From Luca Ferrari
Subject Re: stable for each row before insert trigger
Date
Msg-id CAKoxK+56R4KHM1sUhUbsH2=J3GTUn+HXD6gp9di_nD9UsRQM-w@mail.gmail.com
Whole thread Raw
In response to Re: stable for each row before insert trigger  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Fri, Oct 18, 2019 at 9:16 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= <splarv@ya.ru> writes:
> > According to documentation the words "VOLATILE, STABLE, IMMUTABLE" is somehow useful with trigger functions, for
instancementioned that the AFTER INSERT trigger should be VOLATILE. The question is how this words affect a for each
rowbefore insert trigger? Can be some optimisation here? 
>
> Where did you read that?  There's no optimization that considers the
> volatility of trigger functions --- they'll be called exactly when
> specified, no more or less.

I suspect this sentence could have raised the OP doubt:

"For best optimization results, you should label your functions with
the strictest volatility category that is valid for them."

(from <https://www.postgresql.org/docs/11/xfunc-volatility.html>).

However, here <https://www.postgresql.org/docs/11/trigger-datachanges.html>
it is specified that:

"If your trigger function is written in any of the standard procedural
languages, then the above statements apply only if the function is
declared VOLATILE. Functions that are declared STABLE or IMMUTABLE
will not see changes made by the calling command in any case."

which I hope is the answer to the original question.

Luca



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: stable for each row before insert trigger
Next
From: Luca Ferrari
Date:
Subject: Re: Postgres Point in time Recovery (PITR),