Re: BUG #18647: INSERT statements execute functions twice.

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Todd Brandys <brandystodd(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18647: INSERT statements execute functions twice.
Date: 2024-10-15 09:30:39
Message-ID: 202410150930.prrd666h3um3@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-10-15 09:58:35 BUG #18656: "STABLE" function sometimes does not see changes
Previous Message PG Bug reporting form 2024-10-14 21:58:58 BUG #18655: APT repository shell script doesn't work