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

Started by Ruey-Lung Hsiaoabout 21 years ago2 messages
#1Ruey-Lung Hsiao
rlhsiao@gmail.com

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ruey-Lung Hsiao (#1)
Re: How to deal with order by, group by, distinct for user-defined types

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