pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tod McQuillin <devin@spamcop.net>
To: Carlos <carlos@solaria-mediterranea.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Select distinct and order by.
Date: Tue, 17 Jul 2001 08:25:15 -0500 (CDT)
Message-ID: <Pine.GSO.4.33.0107170818360.13580-100000@sysadmin> (raw)
In-Reply-To: <3B4C1145.97056A0A@solaria-mediterranea.com>

On Wed, 11 Jul 2001, Carlos wrote:

> Select distinct field1, field2 from table1 order by field3;
>
> The value return by PQresultErrorMessage is:
>
> For SELECT DISTINCT, ORDER BY expressions must appear in target list

That's because this query is ambiguous.

What if table1 looks like this:

field1	field2	field3
------	------	------
a	b	1
a	b	3
c	d	2

What should your query return then?  Both

a	b
c	d

and

c	d
a	b

are valid, depending on which 'a b' row was chosen.

If 6.5.3 allowed that, it was a mistake to rely on it because the answer
is undefined.
-- 
Tod McQuillin




view thread (8+ messages)  latest in thread

Message-ID: <Pine.GSO.4.33.0107170818360.13580-100000@sysadmin>
Permalink:  ../Pine.GSO.4.33.0107170818360.13580-100000@sysadmin/
Also on:    postgresql.org/message-id/Pine.GSO.4.33.0107170818360.13580-100000@sysadmin

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: devin@spamcop.net, carlos@solaria-mediterranea.com
  Subject: Re: Select distinct and order by.
  In-Reply-To: <Pine.GSO.4.33.0107170818360.13580-100000@sysadmin>

* 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