[00:02] wgrant: http://pastebin.ubuntu.com/5879216/ without the ORDER BY. It's very strange. [00:02] StevenK: How's it strange? [00:03] I guess I'm used to postgres returning unordered data with no ORDER BY, this is always ordered [00:04] It's not ordered or unordered [00:04] It's ordered by however it happens to come out [00:07] So, I would use a subselect to be simple and sure [00:16] wgrant: So SELECT * FROM (blah..) ORDER BY ... ? [00:17] StevenK: Other way around [00:17] You need to do the sort on the inside, group on the outside [00:17] You don't care about the order of the groups [00:17] You care about the selection of the group result rows [00:37] wgrant: http://pastebin.ubuntu.com/5879285/ [01:38] StevenK: That looks substantially more sensible and likely to work [01:52] wgrant: But they're both the same! [01:53] ... indeed [01:54] I guess it's not at all surprising :) [01:55] GROUP BY with extra columns isn't meant to be permitted [01:55] Since it doesn't have an obvious meaning [01:55] StevenK: Rework to use a subquery with GROUP BY and MAX(date), then join the extra columns in the outer query? [01:55] That has to work [01:56] Probably slow, but we have a proper solution for prod [03:16] wgrant: SELECTing what, though? [03:16] I need to pull out at least one extra column, 'id' [03:25] StevenK: Why? [03:25] StevenK: Select the GROUP BY cols and MAX(date) [03:25] Then join in the outer query, filtering by the GROUP BY cols and date === tasdomas_afk is now known as tasdomas [03:31] wgrant: http://pastebin.ubuntu.com/5879591/ [03:32] dat caps [03:32] Why left join? [03:32] And that join is the wrong way around [03:32] wgrant: I was guessing [03:32] And it'll return duplicates... possibly best to do a second group by on the outer layer, I guess [03:32] Never guess :) [03:33] This is SQL [03:33] Not some other thing that you might have to guess about :) [03:33] LEFT JOIN has a very specific purpoise [03:33] Yeah [03:33] It looks right with JOIN [03:35] I'd hope so [03:35] Given that it's what you want! [03:37] wgrant: http://pastebin.ubuntu.com/5879605/ [03:40] StevenK: I'd add a further GROUP BY on the outside to eliminate dupes with the same key and date [03:42] wgrant: http://pastebin.ubuntu.com/5879610/ [06:04] wgrant: You're happy with that query and I should continue trying to get Django to actually use it? === tasdomas is now known as tasdomas_afk [06:04] StevenK: That sounds reasonable [06:05] Which might involve swearing, throwing screwdrivers at the wall, and if I get really desperate -- gin [06:06] Or "" [06:06] Not quite that simple, since I'd like to deal with the case where only one of object or operation were specified === tasdomas_afk is now known as tasdomas === tasdomas is now known as tasdomas_afk === tasdomas_afk is now known as tasdomas === tasdomas is now known as tasdomas_afk === Ursinha_ is now known as Ursinha === tasdomas_afk is now known as tasdomas === tasdomas is now known as tasdomas_afk === matsubara is now known as matsubara-lunch === matsubara-lunch is now known as matsubara === tasdomas_afk is now known as tasdomas === tasdomas is now known as tasdomas_afk === maxb_ is now known as maxb