Thread: How to deal with order by, group by, distinct for user-defined types

How to deal with order by, group by, distinct for user-defined types

From
Ruey-Lung Hsiao
Date:
Hi,
  I implemented a user-defined type, say X, and when I want to do the 
following queries, Postgresql will complain

CREATE TABLE Table1 ( id integer, object X );

SELECT X, count(*) from Table1
GROUP BY X;

> ERROR:  could not identify an ordering operator for type X
> HINT:  Use an explicit ordering operator or modify the query.
  My question is: how do I find or define ordering operators for my 
user-defined type?

Thanks.

Ruey-Lung Hsiao


Re: How to deal with order by, group by, distinct for user-defined types

From
Tom Lane
Date:
Ruey-Lung Hsiao <rlhsiao@gmail.com> writes:
>    My question is: how do I find or define ordering operators for my 
> user-defined type?

Create a default btree index operator class for the type.  See
http://developer.postgresql.org/docs/postgres/xindex.html
        regards, tom lane