How to compute Fibonacci sequence in SQL

Inspired and simplified from a set of slides on using RDBMS for storing, managing, and querying graphs:

WITH recursive fib(i,j) AS (
    SELECT 0,1
    UNION ALL
    SELECT j, i+j FROM fib WHERE j<1000
)
SELECT i FROM fib

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.