Fastest query for selecting arrays that contain duplicates I'm using Postgres 9.5 and I have a column, named phones, of type text[]. 
I need to find all rows where this column contains duplicates.

I've found this extremely useful set of functions https://github.com/JDBurnZ/postgresql-anyarray and I could use this particular function https://github.com/JDBurnZ/postgresql-anyarray/blob/master/stable/anyarray_uniq.sql

select * from user_info 
where anyarray_uniq(phones) &lt;&gt; phones


I was wondering though if there is a faster way of achieving what I want.
Maybe unnesting the array and using the window functionality would be better? Although I can find my way around SQL, I'm new to Postgres' specific best practices, so any help is welcome. 

Is this better suited for CodeReview?
Among the fastest ways to run such a query is with a specialized index:

create index on user_info ((anyarray_uniq(phones) &lt;&gt; phones)) where
    anyarray_uniq(phones) &lt;&gt; phones;


That way the work of doing the comparisons happens when the records are inserted or updated, not when they are selected.  (To get this to work, you will have to mark as anyarray_uniq as IMMUTABLE, but as far as I can tell this is an accurate way to mark it)