Postgres json_agg includes column header - Incorrect JSON?
问题 Follwoing this post, I have a SQL query that returns the following table: team (json) "{"Name":"TeamA","Players":[{"Name":"CCC"},{"Name":"BBB"}]}" "{"Name":"TeamB","Players":[{"Name":"AAA"},{"Name":"DDD"}]}" I need to aggregate this into JSON to use in my app. I'm using the following: SELECT json_agg(u) FROM (SELECT DISTINCT ON (t.team->>'Name') t.team FROM matches m, json_array_elements(m.match->'Teams') t(team) ORDER BY t.team->>'Name', m.id DESC) AS u Which returns: "[{"team":{"Name":