Select distinct and order by.

From: Carlos <carlos(at)solaria-mediterranea(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Select distinct and order by.
Date: 2001-07-11 08:41:41
Message-ID: 3B4C1145.97056A0A@solaria-mediterranea.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Hi all:

We have developed an aplication in C with postgresql, using libpq. Our
version of development is Postgresql 6.5.3 and it works fine.

Now we are migrating the application to various flavours of Linux
(S.u.s.e 7.1, tha uses postgresql 7.0.3; Debian Potato, that uses
postgresql 7.0.2) and in these dists the next query fails.

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

Whatever this query works fine in postgresql 6.5.3.

Is correct this query and so there was a bug on 6.5.3 or there is a bug
on the new versions?.

Also in certains situations (in versions 7.0.x) this query fails from
libpq:

Select distinct field1, field2, field3 from table1 order by field1,
field2;

but if we copy the statement with mouse and do:

$psql -d ourdb -c "Select distinct field1, field2, field3 from table1
order by field1, field2;" WORKS FINE.

These last situation are in a transaction whith some tables locked, that
aren't table1.

TIA

Carlos.
Solaria Mediterranea, S.L.L:

P.S.: please send me the answers directly, because I isn't subscribed to
the list.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2001-07-11 08:47:33 Re: Problems with PG_DUMP and restore
Previous Message David Stanaway 2001-07-11 05:30:29 cumulative sum in aggregate query.