Skip to content

Instantly share code, notes, and snippets.

@seungha-kim
Created March 2, 2015 17:29
Show Gist options
  • Select an option

  • Save seungha-kim/cc1e2947362ae14d8a05 to your computer and use it in GitHub Desktop.

Select an option

Save seungha-kim/cc1e2947362ae14d8a05 to your computer and use it in GitHub Desktop.
Calculate fibonacci sequence using recursive CTE
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