Thread: How to remove duplicate subqueries

How to remove duplicate subqueries

From
"Andrus"
Date:
I have query

SELECT ...
(
SELECT ... FROM (q1) p1 WHERE ...
UNION ALL
SELECT ... FROM (q1) p2 WHERE ...
) p3
GROUP BY f1,f2,f3

This query contains q1 query twice.
q1 takes long time to execute. PostgreSQL probably will execute it two
times.

How to force PostgreSQL 8.1 to execute q1 only once ?

Andrus.