Re: BUG #12137: ORDER BY with expresion changes the output if added

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12137: ORDER BY with expresion changes the output if added
Date: 2014-12-04 16:01:02
Message-ID: 1417708862460-5829256.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

dima-2 wrote
> FROM "geonames" LEFT OUTER JOIN geoname_names
> ON geoname_names.geoname_id = geonames.geoname_id
> AND geoname_names.name_id IN
> (SELECT name_id FROM geoname_names
> WHERE geoname_names.geoname_id = geonames.geoname_id
> AND geoname_names.language = 'ru'
> ORDER BY geoname_names.short DESC, geoname_names.preffered DESC,
> geoname_names.colloquial, geoname_names.historic
> LIMIT 1

1. This could use aliases since you have repeating table names
2. I would write the above portion as:

geonames LEFT JOIN (
SELDCT DISTINCT ON name_id, geoname_id FROM ... WHERE ... ORDER BY ...
) gnn USING (geoname_id)

3. I would supply a query of the form:

WITH geonames AS ( values (...),(...) )
, geoname_names AS ( values (...) )
<rest of the query here>

And then show what you want the table output of the query to be.

David J.

--
View this message in context: http://postgresql.nabble.com/BUG-12137-ORDER-BY-with-expresion-changes-the-output-if-added-tp5829220p5829256.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message me 2014-12-04 16:03:38 BUG #12146: Crash when using UNION ALL
Previous Message Leonard Meyer 2014-12-04 15:45:06 Re: Infinite waitOnLock