https://dba.stackexchange.com/questions/195104/postgres-grou... has some more info on this
https://dba.stackexchange.com/questions/195104/postgres-grou... has some more info on this
That all said, until that happens, I'd strongly suggest avoiding that functionality since it can lay down some real landmines.
I am trying to work around this but so far my only solution is to parse the SQL of the view definition and extract the information from there. I have it somewhat working but it's a bit complex for my liking..
SELECT DISTINCT ON (vt.id)
row_to_json(vt.*) FROM vt
JOIN vy ON vt.id = vy.tid
WHERE vt.id = 1
AND vy.amount > 1;SELECT posts.*, MAX(COALESCE(comments.created_at, posts.created_at)) AS latest_timestamp FROM posts LEFT OUTER JOINS comments ON posts.id = comments.post_id GROUP BY posts.id ORDER BY latest_timestamp desc
In short, this is sorting posts by the most recent comment, with a fallback to the post date if the post has no comments on it. Hard to get rid of the grouping here and get the same data back.