Created
June 4, 2012 07:06
-
-
Save freeformz/2866845 to your computer and use it in GitHub Desktop.
PL/PGSQL fizzbuzz
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
CREATE OR REPLACE FUNCTION fizzbuzz() | |
RETURNS setof text as $$ | |
BEGIN | |
FOR i IN 1 .. 100 LOOP | |
IF MOD(i, 15) = 0 THEN | |
return next 'FizzBuzz'; | |
ELSIF MOD(i, 5) = 0 THEN | |
return next 'Buzz'; | |
ELSIF MOD(i, 3) = 0 THEN | |
return next 'Fizz'; | |
ELSE | |
return next i::text; | |
END IF; | |
END LOOP; | |
RETURN; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment