Re: ORDER BY <field not in return list>

From: mark(at)mark(dot)mielke(dot)cc
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ORDER BY <field not in return list>
Date: 2005-07-25 22:54:38
Message-ID: 20050725225438.GA20944@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 25, 2005 at 06:11:08PM -0300, Marc G. Fournier wrote:
> Just curious as to whether or not a warning or something should be issued
> in a case like:
> SELECT c.*
> FROM company c, company_summary cs
> WHERE c.id = cs.id
> AND cs.detail = 'test'
> ORDER BY cs.fullname;

> Unless I'm missing something, the ORDER BY clause has no effect, but an
> EXPLAIN shows it does take extra time, obviously ...

Why would it have no effect? If there is a one to many mapping between
fullname and id, and if the rows in c with the same fullname have
different rows in c.*, then it does matter.

For the casual observer, only seeing the output of the table, they would
see a consistent reporting order, but would be unable to derive how the
table rows were sorted. :-)

mark

--
mark(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada

One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...

http://mark.mielke.cc/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2005-07-25 23:06:33 Re: Couple of minor buildfarm issues
Previous Message Marc G. Fournier 2005-07-25 22:25:28 Re: ORDER BY <field not in return list>