Re: Select distinct and order by.

From: Tod McQuillin <devin(at)spamcop(dot)net>
To: Carlos <carlos(at)solaria-mediterranea(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Select distinct and order by.
Date: 2001-07-17 13:25:15
Message-ID: Pine.GSO.4.33.0107170818360.13580-100000@sysadmin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Ruprecht 2001-07-17 13:48:56 First steps in plpgsql - language not recognized?
Previous Message Edipo Elder Fernandes de Melo 2001-07-17 11:56:34 Re: Performance tuning in PostgreSQL?