Chris Campbell <chris(at)bignerdranch(dot)com> writes:
> I don't think this should be happening (PostgreSQL 7.4.1).
Sorry, this isn't a bug. Flattening the subquery is generally desirable
behavior.
I think the easiest way to force the subquery not to be flattened is to
insert a LIMIT or OFFSET clause, viz
SELECT ... FROM (SELECT ... OFFSET 0) query;
regards, tom lane