Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation about recursive functions (CREATE FUNCTION) #3705

Open
2 tasks done
pkoppstein opened this issue Sep 22, 2024 · 2 comments
Open
2 tasks done

documentation about recursive functions (CREATE FUNCTION) #3705

pkoppstein opened this issue Sep 22, 2024 · 2 comments

Comments

@pkoppstein
Copy link

What happens?

It seems that currently functions that are defined recursively will either not compile or will result in a max expression depth limit error, e.g. using the snippet shown below.

It would be helpful if the documentation could not only clarify what should be expected of the current versions of DuckDB, but also indicate the path forward.

Please feel free to interpret this documentation-bug report as a functional-enhancement request :-)

To Reproduce

create or replace function f(n) as (select 1);

create or replace function f(n) as (
  case when n <= 1 then 1
  else f(n-1)
  end
);

select f(3);

OS:

MacOS

DuckDB Version:

any

DuckDB Client:

CLI

Hardware:

No response

Full Name:

Peter Koppstein

Affiliation:

Princeton University

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@soerenwolfers
Copy link
Contributor

same root problem as duckdb/duckdb#13466? to keep things orthogonal, do you have an example that doesn't use the CASE clause?

@hannes hannes transferred this issue from duckdb/duckdb Sep 23, 2024
@pkoppstein
Copy link
Author

@soerenwolfers asked:

do you have an example that doesn't use the CASE clause?

I'm not sure the following will be helpful, but since you asked:

create or replace function f(n) as (select null);

create or replace function f(n) as (
  select coalesce(n, f(n))
  );

select f(1);

In this case, of course, one might be forgiven for expecting the result of f(1) to be 1, but it yields a "Binder error".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants