Created
August 3, 2012 18:44
-
-
Save rapimo/3250341 to your computer and use it in GitHub Desktop.
count occurrences of array values in postgres using hstore
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
SELECT hstore(array_agg(v), array_agg(c::text)) FROM ( | |
SELECT v, COUNT(*) as c ,1 as agg from unnest(ARRAY['foo','bar','baz','foo']) v GROUP BY v) t | |
GROUP BY agg | |
--> "bar"=>"1", "baz"=>"1", "foo"=>"2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
YES