On Tue, Feb 27, 2007 at 12:15:03PM +0100, Robert Partyka wrote:
> Hi,
>
> I found PostgreSQL have strange behaviour with sub-select and pl/pgSQL,
> see the case study at:
> http://www.bobson.pl/pgsql/pgsql_sb1.html
The PostgreSQL optimiser is pretty smart and will pull up simple
sub-selects like yours. If you put your subselect into a view, you'd
also want the optimiser to find the optimal plan, right?
If you want to stop it pulling up the subquery, you can add an OFFSET
0 or ORDER BY or anything that makes it a not-simple subquery. That
tells the planner to leave it alone.
Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.