Blog Archives

Fibonacci Rides Again… and Again

Suppose my previous Fibonacci code should be a function. Here it is: CREATE OR REPLACE FUNCTION fibonacci(int) RETURNS SETOF int AS $BODY$ WITH RECURSIVE t(a, b) AS (     VALUES (1, 1) UNION ALL     SELECT b, a + b FROM t ) SELECT a FROM t  LIMIT $1; $BODY$ IMMUTABLE STRICT LANGUAGE SQL; Take care!

Tagged with: , , , ,
Posted in Coding

Fibonacci Rides Again

Not so long ago I wrote about implementing GCD function in PostgreSQL using CTE. Here I will show how Fibonacci Numbers may be obtained using the same technique. So to have first 16 members of this sequence we should execute

Tagged with: , , , ,
Posted in Coding
Map of wandering

Get every new post delivered to your Inbox.

Join 456 other followers