RosettaCodeData/Task/Anonymous-recursion/DuckDB/anonymous-recursion.duckdb
2025-08-11 18:05:26 -07:00

11 lines
264 B
Text

create or replace function fib(n) as (
if ( n < 0, error('negative arguments not allowed'),
(with recursive fib(i,e,f) as (
select 1, 1, 1
union all
select i+1, e+f, e from fib
where i <= n)
select last(f order by i)
from fib)
)
);