Vik Reykja <vikreykja@gmail.com> writes:
> Hello. It took me a while to get a version of this that was independent of
> my data, but here it is. I don't understand what's going wrong but if you
> change any part of this query (or at least any part I tried), the correct
> result is returned.
Huh. 9.1 gets the wrong answer too, so this isn't a (very) new bug;
but curiously, 8.4 and 9.0 seem to get it right. I think this is
probably related somehow to Adam Mackler's recent report --- multiple
scans of the same CTE seems to be a bit of a soft spot :-(
regards, tom lane