| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Tomasz Myrta <jasiek(at)klaster(dot)net> | 
| Cc: | pgsql-sql(at)postgresql(dot)org | 
| Subject: | Re: order by and aggregate | 
| Date: | 2003-01-06 16:34:35 | 
| Message-ID: | 14734.1041870875@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
Tomasz Myrta <jasiek(at)klaster(dot)net> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomasz Myrta | 2003-01-06 16:35:54 | Re: order by and aggregate | 
| Previous Message | dev | 2003-01-06 15:59:51 | Re: order by and aggregate |