Skip to content

Instantly share code, notes, and snippets.

@kongelaks
Created January 15, 2013 15:22
Show Gist options
  • Save kongelaks/4539387 to your computer and use it in GitHub Desktop.
Save kongelaks/4539387 to your computer and use it in GitHub Desktop.
get distribution of array values in a postgres array field
select count(*), unnest("FIELD_NAME") as field from "TABLE" group by field;
@jingerso
Copy link

gist should be like this...

dbkaigoaig2h9j=> select count(*), unnest("RESIBASE") as field from aarrets2."Property" group by field;
count | field
-------+--------------------
104 | Crawl
185 | Partially Finished
244 | Walkout
126 | Daylight
247 | Finished
147 | Egress
77 | Slab
822 | Full
104 | Partial
55 | Michigan
(10 rows)

@jingerso
Copy link

dbkaigoaig2h9j=> select count(*), unnest("RENTBASE") as field from aarrets2."Property" group by field;
count | field
-------+--------------------
62 | Full
9 | Partial
16 | Partially Finished
16 | Walkout
24 | Finished
7 | Egress
11 | Crawl
18 | Slab
6 | Daylight
7 | Michigan
(10 rows)

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