pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #12137: ORDER BY with expresion changes the output if added
Date: Thu, 4 Dec 2014 09:01:02 -0700 (MST)
Message-ID: <1417708862460-5829256.post@n5.nabble.com> (raw)
In-Reply-To: <20141204064346.2573.21378@wrigleys.postgresql.org>
References: <20141204064346.2573.21378@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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-tp5829220...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <1417708862460-5829256.post@n5.nabble.com>
Permalink:  ../1417708862460-5829256.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1417708862460-5829256.post@n5.nabble.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: david.g.johnston@gmail.com
  Subject: Re: BUG #12137: ORDER BY with expresion changes the output if added
  In-Reply-To: <1417708862460-5829256.post@n5.nabble.com>
  References: <20141204064346.2573.21378@wrigleys.postgresql.org> <1417708862460-5829256.post@n5.nabble.com>

* 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