Re: BUG #18647: INSERT statements execute functions twice. - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #18647: INSERT statements execute functions twice.
Date
Msg-id 202410150930.prrd666h3um3@alvherre.pgsql
Whole thread Raw
In response to Re: BUG #18647: INSERT statements execute functions twice.  (Todd Brandys <brandystodd@gmail.com>)
List pgsql-bugs
On 2024-Oct-09, Todd Brandys wrote:

> CREATE FUNCTION uuid.nextval ( IN i_regclass pg_catalog.regclass ) RETURNS pg_catalog.uuid AS $$
> SELECT raise.notice('***** uuid.nextval');
>     WITH t_pool AS (
>         SELECT      pool.id_entity AS id_entity,
>                     pool.uuid AS uuid
>             FROM    uuid.pool
>             WHERE   pool.id_entity = i_regclass
>             ORDER BY pg_catalog.RANDOM() ASC
>             LIMIT   1

Not related to your reported problem, but note that the "order by
random()" pattern might be slow as uuid.pool becomes large.  Andrew
Gierth wrote a blog post on this topic awhile ago which may be helpful:
https://blog.rhodiumtoad.org.uk/2009/03/08/selecting-random-rows-from-a-table/

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"Before you were born your parents weren't as boring as they are now. They
got that way paying your bills, cleaning up your room and listening to you
tell them how idealistic you are."  -- Charles J. Sykes' advice to teenagers



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18655: APT repository shell script doesn't work
Next
From: PG Bug reporting form
Date:
Subject: BUG #18656: "STABLE" function sometimes does not see changes