pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomasz Myrta <jasiek@klaster.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: order by and aggregate
Date: Mon, 06 Jan 2003 11:34:35 -0500
Message-ID: <14734.1041870875@sss.pgh.pa.us> (raw)
In-Reply-To: <3E197A39.8070808@klaster.net>
References: <3E197A39.8070808@klaster.net>

Tomasz Myrta <jasiek@klaster.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



view thread (9+ messages)  latest in thread

Message-ID: <14734.1041870875@sss.pgh.pa.us>
Permalink:  ../14734.1041870875@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14734.1041870875@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jasiek@klaster.net
  Subject: Re: order by and aggregate
  In-Reply-To: <14734.1041870875@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox