Skip to content

Instantly share code, notes, and snippets.

@jhorstmann
Last active April 5, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorstmann/ea026bd84c84a755b957 to your computer and use it in GitHub Desktop.
Save jhorstmann/ea026bd84c84a755b957 to your computer and use it in GitHub Desktop.
WITH n AS (SELECT 100 AS n)
SELECT COALESCE(fizz || buzz, fizz, buzz, i::text)
FROM n
CROSS JOIN LATERAL generate_series(1, n) AS i
LEFT JOIN LATERAL (SELECT i, 'fizz'::text AS fizz
FROM generate_series(0, n, 3) AS i) fizz USING(i)
LEFT JOIN LATERAL (SELECT i, 'buzz'::text AS buzz
FROM generate_series(0, n, 5) AS i) buzz USING(i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment