I have a table on pgsql with names (having more than 1 mio. rows), but I have also many duplicates. I select 3 fields: id, name, metadata
id
name
metadata
To do a distinct on n columns:
select distinct on (col1, col2) col1, col2, col3, col4 from names