select -- this line is the DISTINCT ON clause: distinct on (key) -- the select list follows: key, source from yourtable -- often you'd want an order by clause -- to control which rows are discarded -- In this case it does not seem to be important ;