From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | brandystodd(at)gmail(dot)com |
Subject: | BUG #18647: INSERT statements execute functions twice. |
Date: | 2024-10-08 19:11:52 |
Message-ID: | 18647-8ac606f2f23b1621@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 18647
Logged by: Todd Brandys
Email address: brandystodd(at)gmail(dot)com
PostgreSQL version: 16.1
Operating system: Linux
Description:
I am writing a function uuid.nextval(...) that returns a UUID value from a
preallocated pool of values known to be unique. I was seeing the pool
decrease by two per INSERT, and I found something interesting when I raised
a NOTICE in the nextval() function. Here are three INSERTs, and only the
last will result in nextval() being called once. Is this a known issue?
What would be the reason for calling the functions in the VALUES list twice?
For the foreseeable future, this means that the most efficient method would
be to place all functions in a FROM list.
dchain=# INSERT INTO public.party
VALUES ( uuid.nextval('party'), utc.get_timestamp(),
SESSION_USER::regrole, uuid.v4() );
NOTICE: ***** uuid.nextval
DETAIL:
HINT:
NOTICE: ***** uuid.nextval
DETAIL:
HINT:
INSERT 0 1
dchain=# INSERT INTO public.party
SELECT uuid.nextval('party'::regclass) AS party,
utc.get_timestamp() AS date_upated,
SESSION_USER::regrole AS user_updated,
uuid.v4() AS organization;
NOTICE: ***** uuid.nextval
DETAIL:
HINT:
NOTICE: ***** uuid.nextval
DETAIL:
HINT:
INSERT 0 1
dchain=# INSERT INTO public.party
SELECT d_party AS party,
utc.get_timestamp() AS date_upated,
SESSION_USER::regrole AS user_updated,
uuid.v4() AS organization
FROM uuid.nextval('party'::regclass) AS d_party;
NOTICE: ***** uuid.nextval
DETAIL:
HINT:
INSERT 0 1
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2024-10-08 20:04:17 | Re: BUG #18647: INSERT statements execute functions twice. |
Previous Message | Tom Lane | 2024-10-08 14:05:08 | Re: pg_dump throwing segfault error during backup |