Re: Unexpected results from CALL and AUTOCOMMIT=off

From: Victor Yegorov <vyegorov(at)gmail(dot)com>
To: Pierre Forstmann <pierre(dot)forstmann(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unexpected results from CALL and AUTOCOMMIT=off
Date: 2024-06-03 18:15:07
Message-ID: CAGnEbojf5Awm862ghvooLku6mm0m4yF60PyHQxCinM8pn01sbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

пн, 3 июн. 2024 г. в 20:40, Pierre Forstmann <pierre(dot)forstmann(at)gmail(dot)com>:

> You declared function f_get_x as stable which means:
>
> …
>
> If you remove stable from function declaration, it works as expected:
>

Well, I checked
https://www.postgresql.org/docs/current/xfunc-volatility.html
There's a paragraph describing why STABLE (and IMMUTABLE) use different
snapshots:

> For functions written in SQL or in any of the standard procedural
languages, there is a second important property determined by the
volatility category, namely the visibility of any data changes that have
been made by the SQL command that is calling the function. A > VOLATILE
function will see such changes, a STABLE or IMMUTABLE function will not.
This behavior is implemented using the snapshotting behavior of MVCC (see
Chapter 13): STABLE and IMMUTABLE functions use a snapshot established as
of the start of the
> calling query, whereas VOLATILE functions obtain a fresh snapshot at the
start of each query they execute.

But later, docs state, that

> Because of this snapshotting behavior, a function containing only SELECT
commands can safely be marked STABLE, even if it selects from tables that
might be undergoing modifications by concurrent queries. PostgreSQL will
execute all commands of a STABLE function using the snapshot established
for the calling query, and so it will see a fixed view of the database
throughout that query.

And therefore I assume STABLE should work in this case. Well, it seems not
to.

I assume there's smth to do with implicit BEGIN issued in non-AUTOCOMMIT
mode and non-atomic DO block behaviour.

--
Victor Yegorov

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-06-03 19:28:10 Re: Unexpected results from CALL and AUTOCOMMIT=off
Previous Message Pierre Forstmann 2024-06-03 17:40:24 Re: Unexpected results from CALL and AUTOCOMMIT=off

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2024-06-03 18:30:21 Re: Psql meta-command conninfo+
Previous Message Nathan Bossart 2024-06-03 18:03:31 Re: Will there be https://wiki.postgresql.org/wiki/PgCon_2024_Developer_Unconference ?