Re: BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own - Mailing list pgsql-bugs

From Yushu Chen
Subject Re: BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own
Date
Msg-id CAP5x3pZvk6D9b9mmKBEYKqZvJcDpH5OfZ419aVgzr+xXpo4O=w@mail.gmail.com
Whole thread Raw
In response to BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own
List pgsql-bugs
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?
Can someone from the Core team confirm this?

I will try to look into this command, before someone can give a clear clarification.

On Thu, Aug 28, 2025 at 8:18 PM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      19034
Logged by:          Katja Henke
Email address:      katja.henke@foo.ag
PostgreSQL version: 15.3
Operating system:   Linux
Description:       

An existing function can be converted into a recursive function that uses
sql_body. But it is not possible to create this same recursive function
using CREATE FUNCTION. In other words: if you managed to have a recursive
function with sql_body in your database, you can't simply restore a dump of
this database.

The following statement results in
ERROR:  42883: function pg_temp.do_something(integer) does not exist

CREATE FUNCTION pg_temp.do_something(int) RETURNS int
LANGUAGE sql
RETURN CASE WHEN $1 % 2 = 1 THEN pg_temp.do_something($1 + 1) ELSE $1 END;

But the combination of the following statements works. It does not matter if
the first function uses sql_body or a string constant.

CREATE FUNCTION pg_temp.do_something(int) RETURNS int
LANGUAGE sql
RETURN 42;

CREATE OR REPLACE FUNCTION pg_temp.do_something(int) RETURNS int
LANGUAGE sql
RETURN CASE WHEN $1 % 2 = 1 THEN pg_temp.do_something($1 + 1) ELSE $1 END;

pgsql-bugs by date:

Previous
From: Raghvendra Mishra
Date:
Subject: Postgres immediately closing connection when `systemctl reboot` command is fired.
Next
From: Greg Sabino Mullane
Date:
Subject: Re: empty,query_id, pg_stat_activity