Created
March 2, 2015 17:29
-
-
Save seungha-kim/cc1e2947362ae14d8a05 to your computer and use it in GitHub Desktop.
Calculate fibonacci sequence using recursive CTE
This file contains hidden or 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 fibo(ord, m, n) as ( | |
| values (1, 1, 1) | |
| union all | |
| select ord+1, n, m+n from fibo where ord < 10 | |
| ) select m from fibo; | |
| /* result : | |
| m | |
| ---- | |
| 1 | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 8 | |
| 13 | |
| 21 | |
| 34 | |
| 55 | |
| (10 rows) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment