Thread: order by for user defined types

order by for user defined types

From
Kjetil Haaland
Date:
Hello

I have a defined my own type that i use in postgres. I have made some
operators like >, => etc. so i can use it in a where clause in a query. I am
now wondering if it is possible to do the same for order by? It probably is,
since i get an error saying:
"could not identify an ordering operator for type alignres"
and a hint:
"Use an explicit ordering operator or modify the query".

If i am going to write my own ordering operator, is it then possible to call
the ordering operator function that postgres already has inside my function
and specify what to order on, or do i have to write my own sorting algorithm
too?

thanks

-Kjetil

Re: order by for user defined types

From
Tom Lane
Date:
Kjetil Haaland <kjetil.haaland@student.uib.no> writes:
> I have a defined my own type that i use in postgres. I have made some
> operators like >, => etc. so i can use it in a where clause in a query. I am
> now wondering if it is possible to do the same for order by?

You need to define a default btree index opclass for your datatype.  See
the chapter "Interfacing Extensions to Indexes" in the documentation.

            regards, tom lane