Removing duplicates in a PostgreSQL array
Moof Mayeda


just writing to note that the use of UNNEST() in SELECT clauses is considered deprecated and may be invalid in future releases of PostgreSQL.

There is an equivalent variant of your idea that moves the UNNEST() into the FROM clause and gets rid of the GROUP BY at the same time:

SELECT v.song_id, genre 
FROM versions v, LATERAL UNNEST(STRING_TO_ARRAY(v.genre_list, ‘, ‘)) AS genre;