Created
February 11, 2015 08:01
-
-
Save komamitsu/c2a5c46a22d765df5aa2 to your computer and use it in GitHub Desktop.
Fibonacci number with "with recursive" in PostgreSQL
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
with recursive r(a, b) as ( | |
select 0::int, 1::int | |
union all | |
select b, a + b from r where b < 1000 | |
) | |
select a from r; | |
a | |
----- | |
0 | |
1 | |
1 | |
2 | |
3 | |
5 | |
8 | |
13 | |
21 | |
34 | |
55 | |
89 | |
144 | |
233 | |
377 | |
610 | |
987 | |
(17 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment