DISTINCT ON in an aggregate function in postgres DISTINCT ON in an aggregate function in postgres json json