Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Created December 7, 2021 03:06
Show Gist options
  • Save ddrscott/01917c6433c18bc6f7c278161957734a to your computer and use it in GitHub Desktop.
Save ddrscott/01917c6433c18bc6f7c278161957734a to your computer and use it in GitHub Desktop.
Simple non-repeating pairs of numbers in all combinations
WITH inputs AS (
SELECT
row_number() over () as idx,
letter
FROM unnest(ARRAY['a', 'b', 'c', 'd']) letters(letter)
)
SELECT
a.letter,
b.letter
FROM inputs a, inputs b
WHERE a.idx < b.idx;
@ddrscott
Copy link
Author

ddrscott commented Dec 7, 2021

It works.

 letter | letter 
--------+--------
 a      | b
 a      | c
 a      | d
 b      | c
 b      | d
 c      | d
(6 rows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment