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 1uuBpn-004J56-09 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Sep 2025 15:25:11 +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 1uuBpm-00HCYU-3E for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Sep 2025 15:25:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uuBpl-00HCYL-Qv for pgsql-bugs@lists.postgresql.org; Thu, 04 Sep 2025 15:25:10 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uuBpj-000WkK-2c for pgsql-bugs@lists.postgresql.org; Thu, 04 Sep 2025 15:25:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 584FOwXp1030107; Thu, 4 Sep 2025 11:24:58 -0400 From: Tom Lane To: Yushu Chen cc: katja.henke@foo.ag, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own In-reply-to: References: <19034-de0857b4f94ec10c@postgresql.org> Comments: In-reply-to Yushu Chen message dated "Thu, 04 Sep 2025 17:03:34 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1030105.1756999498.1@sss.pgh.pa.us> Date: Thu, 04 Sep 2025 11:24:58 -0400 Message-ID: <1030106.1756999498@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Yushu Chen writes: > I ran a test on my local postgresql server, resulting in the same error as > described. > However, I wonder about the necessity of supporting recursive functions in > the CREATE FUNCTION command alone? This is a general property of SQL-standard functions: all objects referenced in the function body have to exist before creating the function. Poking holes in that property would largely defeat the point of having this type of function. You could imagine supporting the case by making CREATE FUNCTION act as though it were CREATE FUNCTION foo ... AS $$something dummy$$; CREATE OR REPLACE FUNCTION foo ... BEGIN real-body END; However, that would be a significant amount of work to implement and it'd about double the cost of doing CREATE FUNCTION. Note that this cost would probably have to be incurred for every SQL-standard function, as I see no good way to detect whether the body contains a recursive reference in advance of parsing it. Given that recursive SQL functions are a tiny-minority use case and there's already a perfectly serviceable way to make them (ie use an old-style body), I seriously doubt that we'll do anything about this request. regards, tom lane