Skip to content

Instantly share code, notes, and snippets.

@realFranco
Last active May 13, 2021 21:35
Show Gist options
  • Save realFranco/c99453575e69b5e23a3415e6b034037a to your computer and use it in GitHub Desktop.
Save realFranco/c99453575e69b5e23a3415e6b034037a to your computer and use it in GitHub Desktop.
Using Procedural Language PostgreSQL for a Fibonacci number implementation.
-- Trying a fibonacci on pl/pgsql
create or replace function fibonacci( step integer )
returns integer as
$$
begin
-- raise info 'step %', step;
if step = 0 then
return 0;
else
if step = 1 then
return 1;
else
return fibonacci( step := step - 1 ) + fibonacci( step := step - 2 );
end if;
end if;
end;
$$
language plpgsql;
-- Test it:
-- select fibonacci(10); -- 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment