CaffeineIV
CaffeineIV

Reputation: 147

PostGres Error When Using Distinct : postgres ERROR: could not identify an ordering operator for type record

** EDIT **

Nevermind, just needed to take out the parens...

I get this error: ERROR: could not identify an ordering operator for type record when trying to use DISTINCT

Here's the query:

select DISTINCT(g.fielda, g.fieldb, r.type) 
from fields g LEFT JOIN types r ON g.id = r.id;

And the errors:

ERROR:  could not identify an ordering operator for type record
HINT:  Use an explicit ordering operator or modify the query.

********** Error **********

ERROR: could not identify an ordering operator for type record
SQL state: 42883
Hint: Use an explicit ordering operator or modify the query.

Upvotes: 3

Views: 14133

Answers (1)

Andrew Aylett
Andrew Aylett

Reputation: 40730

As I think you've worked out, you don't want the parentheses after DISTINCT. They look like they should be parameterising DISTINCT, but they actually serve to make the query return a single column of record type instead of multiple columns. The DISTINCT operator then tries to work on the record and finds that you've not defined an ordering on that record.

If you want DISTINCT to work on a subset of your return values, use DISTINCT ON.

Upvotes: 2

Related Questions