Correct SQL statement for postgres

In standard sql, join binds tighter than comma, so we were joining on the wrong table. Postgres follows the standard (apparently).
This commit is contained in:
David Baker 2016-05-04 13:19:59 +01:00
parent 8cc82aad87
commit 80be396464
1 changed files with 3 additions and 2 deletions

View File

@ -120,14 +120,15 @@ class EventPushActionsStore(SQLBaseStore):
sql = (
"SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions, "
"e.received_ts "
"FROM event_push_actions AS ep, ("
"FROM ("
" SELECT room_id, user_id, "
" max(topological_ordering) as topological_ordering, "
" max(stream_ordering) as stream_ordering "
" FROM events"
" NATURAL JOIN receipts_linearized WHERE receipt_type = 'm.read'"
" GROUP BY room_id, user_id"
") AS rl"
") AS rl,"
" event_push_actions AS ep"
" INNER JOIN events AS e USING (room_id, event_id)"
" WHERE"
" ep.room_id = rl.room_id"