Skip to content

Instantly share code, notes, and snippets.

@knmkr
Created May 18, 2015 05:44
Show Gist options
  • Save knmkr/ae696fd70d600d9c8577 to your computer and use it in GitHub Desktop.
Save knmkr/ae696fd70d600d9c8577 to your computer and use it in GitHub Desktop.
Sort and uniq example in PostgreSQL with intarray extension.
CREATE EXTENSION intarray;
SELECT uniq(sort(ARRAY[3,2,1,4,3]));
-- uniq
-- -----------
-- {1,2,3,4}
SELECT unnest(uniq(sort(ARRAY[3,2,1,4,3])));
-- unnest
-- --------
-- 1
-- 2
-- 3
-- 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment