X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2F435474E42 for ; Thu, 13 Feb 2003 14:27:20 -0500 (EST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 06E484759AF for ; Thu, 13 Feb 2003 14:27:18 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 49E47D682; Thu, 13 Feb 2003 11:27:18 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 3F79B5C0D; Thu, 13 Feb 2003 11:27:18 -0800 (PST) Date: Thu, 13 Feb 2003 11:27:18 -0800 (PST) From: Stephan Szabo To: Nicholas Allen Cc: Tom Lane , Peter Childs , Subject: Re: Debugging postmaster to fix possible bug in Postgres? In-Reply-To: <200302131828.50026.nallen@freenet.co.uk> Message-ID: <20030213110929.X47380-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/294 X-Sequence-Number: 11692 On Thu, 13 Feb 2003, Nicholas Allen wrote: > Because the WHERE clause is directly affected by the ORDER BY clause. If you > leave out the order by clause then the row count will be completely different > and therefore wrong. The ORDER BY clause is just as important as the WHERE > clause when counting rows. It should be possible to get a count for the rows > for any query that can be done which can return row data as I understand it. WHERE effectively occurs before ORDER BY, so unless it's an order by in a subselect I don't think the where clause can be affected by the ORDER BY legally. select count(*) from foo where a<3 order by a; and select count(*) from foo where a<3; must give the same results AFAICT. > I have tried to find a definition for SQL SELECT command but everywhere I have > looked so far makes no mention of this being invalid SQL syntax. Can you let > me know where you got this information? I think this may follow from the syntax rules of the general select from a strict reading of SQL92 20.2 and 9.7 (which implies to me that any form of select a from table order by b; would be an extension) or a looser reading of syntax rule 7 in 9.7 which disallows value expressions referencing a column that wasn't specified in a set function specification for non-grouped tables.