pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: katja.henke@foo.ag
Subject: BUG #19034: Recursive function with sql_body can replace an existing function but can not be created on it's own
Date: Thu, 28 Aug 2025 12:09:30 +0000
Message-ID: <19034-de0857b4f94ec10c@postgresql.org> (raw)

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;



view thread (13+ messages)  latest in thread

Message-ID: <19034-de0857b4f94ec10c@postgresql.org>
Permalink:  ../19034-de0857b4f94ec10c@postgresql.org/
Also on:    postgresql.org/message-id/19034-de0857b4f94ec10c@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, katja.henke@foo.ag
  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: <19034-de0857b4f94ec10c@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox