Tomasz Myrta <[EMAIL PROTECTED]> writes:
> I found I can obey this using subselect:
> select
> maxsum(X.value)
> from
> (select value
> from some_table
> order by some_field) X
> I can't create subselect, because I want to change this query into a
> view. In my case postgresql doesn't use indexes on subselect inside a view.
I don't understand what you think is wrong with this solution. It works
fine for me:
regression=# create view vv as
regression-# select max(unique1) from (select unique1 from tenk1
regression(# order by unique2) x;
CREATE VIEW
regression=# explain select * from vv;
QUERY PLAN
---------------------------------------------------------------------------------------------------
Subquery Scan vv (cost=523.00..523.00 rows=1 width=8)
-> Aggregate (cost=523.00..523.00 rows=1 width=8)
-> Subquery Scan x (cost=0.00..498.00 rows=10000 width=8)
-> Index Scan using tenk1_unique2 on tenk1 (cost=0.00..498.00
rows=10000 width=8)
(4 rows)
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org