GROUP BY in Postgres - no equality for JSON data type?
Shorter, faster and more elegant with a LATERAL
join:
SELECT DISTINCT ON (t.team->>'Name') t.teamFROM matches m, json_array_elements(m.match->'Teams') t(team);ORDER BY t.team->>'Name', m.id DESC; -- to get the "last"
If you just want distinct teams, the ORDER BY
can go. Related:
JSON and equality
There is no equality operator for the json
data type in Postgres, but there is one for jsonb
(Postgres 9.4+):