Skip site navigation (1) Skip section navigation (2)

Re: Multi ordered select and indexing

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Antal Attila" <antal(dot)attila(at)ritek(dot)hu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Multi ordered select and indexing
Date: 2004-04-29 19:34:13
Message-ID: 14669.1083267253@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
"Antal Attila" <antal(dot)attila(at)ritek(dot)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

In response to

pgsql-sql by date

Next:From: Roelant OssewaardeDate: 2004-04-29 20:26:40
Subject: Re: Use arrays or not?
Previous:From: Josh BerkusDate: 2004-04-29 19:20:01
Subject: Re: Equivalant of SQL Server's Nchar and NVARCHAR

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group