Last active
May 13, 2021 21:35
-
-
Save realFranco/c99453575e69b5e23a3415e6b034037a to your computer and use it in GitHub Desktop.
Using Procedural Language PostgreSQL for a Fibonacci number implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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