Re: Multi ordered select and indexing - Mailing list pgsql-sql

From Tom Lane
Subject Re: Multi ordered select and indexing
Date
Msg-id 14669.1083267253@sss.pgh.pa.us
Whole thread Raw
In response to Multi ordered select and indexing  ("Antal Attila" <antal.attila@ritek.hu>)
List pgsql-sql
"Antal Attila" <antal.attila@ritek.hu> writes:
>   CREATE OPERATOR CLASS int4_reverse_order_ops  
>     FOR TYPE int4 USING btree AS  
>         OPERATOR        1       /< ,  
>         OPERATOR        2       /<= ,  
>         OPERATOR        3       /= ,  
>         OPERATOR        4       />= ,  
>         OPERATOR        5       /> ,  
>         FUNCTION        1       int4_reverse_order_cmp(int4, int4);  

This is the wrong way to go about it.  A useful descending-order opclass
simply rearranges the logical relationships of the standard comparison
operators.  You do need a new comparison function, but nothing else:
 CREATE OPERATOR CLASS int4_reverse_order_ops     FOR TYPE int4 USING btree AS         OPERATOR        1       > ,
  OPERATOR        2       >= ,         OPERATOR        3       = ,         OPERATOR        4       <= ,
OPERATOR       5       < ,         FUNCTION        1       int4_reverse_order_cmp(int4, int4);  
 

Now you can just use ASC/DESC in your ORDER BY ...
        regards, tom lane


pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Equivalant of SQL Server's Nchar and NVARCHAR
Next
From: Pallav Kalva
Date:
Subject: Permissions not working