select distinct on (id) id, attribute
from like_this
order by id, random()
Se ti serve solo la colonna dell'attributo:
select distinct on (id) attribute
from like_this
order by id, random()
Nota che devi ancora ordinare tramite id prima perché è una colonna del distinct on .
Se vuoi solo gli attributi distinti:
select distinct attribute
from (
select distinct on (id) attribute
from like_this
order by id, random()
) s