RosettaCodeData/Task/Anonymous-recursion/DuckDB/anonymous-recursion.duckdb

12 lines
264 B
Plaintext

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)
)
);