public inbox for [email protected]  
help / color / mirror / Atom feed
'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running
2+ messages / 2 participants
[nested] [flat]

* 'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running
@ 2022-04-20 18:02 PG Doc comments form <[email protected]>
  2022-04-20 20:52 ` Re: 'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running David G. Johnston <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Doc comments form @ 2022-04-20 18:02 UTC (permalink / raw)
  To: [email protected]; +Cc: [email protected]

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/14/sql-createfunction.html
Description:

The page does not mention what is the default behavior whenever a function
is replaced while the same function is being used in another
query/transaction.

Does the query fail? Does the 'CREATE OR REPLACE' operation fail? Does the
query finish before the function is replaced?

As a side note, my interest in this came from our need to use 'C-Language
Functions', aka binary functions, so it would be neat to also add what is
the behavior on those as well, if there's any difference.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: 'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running
  2022-04-20 18:02 'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running PG Doc comments form <[email protected]>
@ 2022-04-20 20:52 ` David G. Johnston <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2022-04-20 20:52 UTC (permalink / raw)
  To: [email protected]; Pg Docs <[email protected]>

On Wed, Apr 20, 2022 at 12:50 PM PG Doc comments form <
[email protected]> wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/14/sql-createfunction.html
> Description:
>
> The page does not mention what is the default behavior whenever a function
> is replaced while the same function is being used in another
> query/transaction.
>
> Does the query fail? Does the 'CREATE OR REPLACE' operation fail? Does the
> query finish before the function is replaced?
>
> As a side note, my interest in this came from our need to use 'C-Language
> Functions', aka binary functions, so it would be neat to also add what is
> the behavior on those as well, if there's any difference.
>

IIUC pg_proc is administered using MVCC behavior just like any other
table.  What you experience will be subject to your isolation mode but in
no case will a single command's execution see different versions nor will
such execution prevent the "replace"ment of the function with a newer
version.

Absent guidance to the contrary I wouldn't expect C language functions to
behave any differently than any others.  But that just pertains to the
"REPLACE" aspect.  You need to read the notes about C language functions to
get the rest of the story (and you likely wouldn't need to "replace" a
C-langauge function entry because of this different loading/compiling
mechanism). Namely:

https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-DYNLOAD

In short, C-language functions, referenced simply by name and module, and
pre-compiled, do not have a mechanism to invalidate the cache like pl/pgsql
functions do.  Other languages may involve yet other dynamics.

David J.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-04-20 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 18:02 'CREATE OR REPLACE FUNCTION' behavior whenever a transaction is running PG Doc comments form <[email protected]>
2022-04-20 20:52 ` David G. Johnston <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox