Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0dtD-00CTfn-Qc for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Oct 2024 09:30:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t0dtB-005ACM-4A for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Oct 2024 09:30:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0dtA-005ACE-8T for pgsql-bugs@lists.postgresql.org; Tue, 15 Oct 2024 09:30:49 +0000 Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0dt7-0019uX-5Q for pgsql-bugs@lists.postgresql.org; Tue, 15 Oct 2024 09:30:47 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id BE2D711401E8; Tue, 15 Oct 2024 05:30:42 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Tue, 15 Oct 2024 05:30:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1728984642; x= 1729071042; bh=K73zNKJVW6NtYNabONazdnb8ykQuSnXCIsMVGaNVpWc=; b=h 1uVeoqLA1kGjbwbCkc0v8nx0iaq/01WT1WuidjYBMe0kiez2XlEbDn8QFv/Wu/Lx POuJhouwi/GROVpSLh4O6IIB+cjWjsWLeLX0w3914rwhlhE+I+duTdqSk1dylJvx KmJF/LlMyyviAr9fieXxOc2tmbaPSd2UBVMFbFFvYoDhCHIjUHclAaczDIKNqopT OjJK85V7UtTHPrD6nFQUPFc8XNQ88ks/05CmszXdHyzqjGmvh/FpiduE6FRyn5h/ r2kxYSm4kTrqymMy2fDOHUMtKWgTDnYZjtcG/KRIzNBaPyZcd+PRuqmTG6cJQ3UP C9wrF6MluqYE5UXU+s4Tw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdegjedgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeen ucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepjeeijeduhfetgeduffduhfdt ledviefhleeiieejieekueeugfefudekteehjeevnecuffhomhgrihhnpehrhhhoughiuh hmthhorggurdhorhhgrdhukhdpvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvse grlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepsghrrghnugihshhtohguugesghhmrghilhdrtghomhdprh gtphhtthhopegurghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilhdrtghomhdprhgt phhtthhopehpghhsqhhlqdgsuhhgsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorh hg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Oct 2024 05:30:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1728984640; bh=1AUPJx0kIbxJlf22W19qqWkScKnxBvw+G+YmUNRY9JQ=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=jpdJT1TM24jTFEY1a2ZePLGjjAjBksBV5cMC7zjYKLJsk/vX4P7KJadZDyt91BRCK fv5IQBjNDMsa13Vuyo7I+4r4KcsgehPoya0qqrhpp8p6cRJ9Tp2Pg9K3wA9szXwcFS 9R4wMg3ho6SiwkiYe58jcwhFp0TL46PkvAxmSsAsUMvze1sTtSeaBKliHeNFqd/Xxe sNrnjmEFmBHcOJk5W/yrIHnyVO6Cx6kOwO11lnQIEOhoQK50L02OkpyekIZAPlktUD NxaT+xg+aa3QH13mYIFtPUZEQaJh2I3dL+JnI+ezAYD06tdxJVgWgmW/9239rlcpmp YxT5nGIU7WxMQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 0232F9B; Tue, 15 Oct 2024 11:30:39 +0200 (CEST) Date: Tue, 15 Oct 2024 11:30:39 +0200 From: Alvaro Herrera To: Todd Brandys Cc: "David G. Johnston" , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18647: INSERT statements execute functions twice. Message-ID: <202410150930.prrd666h3um3@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8394679D-5AA0-4727-A28A-BE08A0A11103@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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