Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 72F18476BBD for ; Mon, 6 Jan 2003 12:05:07 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 046F1476A0A for ; Mon, 6 Jan 2003 12:04:59 -0500 (EST) Received: from klaster.net (pc54.krakow.cvx.ppp.tpnet.pl [213.76.38.54]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 16C482B21E; Mon, 6 Jan 2003 18:03:31 +0100 (CET) Message-ID: <3E19B7ED.4020901@klaster.net> Date: Mon, 06 Jan 2003 18:07:57 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2b) Gecko/20021016 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: order by and aggregate References: <3E197A39.8070808@klaster.net> <14734.1041870875@sss.pgh.pa.us> In-Reply-To: <3E197A39.8070808@klaster.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/43 X-Sequence-Number: 10908 Tom Lane wrote: > 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) > OK, your view is ok. I think, you don't remember my questions about "joining views" and "sub-select with aggregate" dated on 2002-10-23, so I qoute your answer on that question (joining views): >I think this is the same issue that Stephan identified in his response >to your other posting ("sub-select with aggregate"). When you write > FROM x join y using (col) WHERE x.col = const >the WHERE-restriction is only applied to x. I'm afraid you'll need >to write > FROM x join y using (col) WHERE x.col = const AND y.col = const >Ideally you should be able to write just > FROM x join y using (col) WHERE col = const >but I think that will be taken the same as "x.col = const" :-( I have the same problem here, query is a bit complicated and has some_table join (subselect) X using (some_field) which doesn't work. Regards, Tomasz Myrta