pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Antal Attila <antal.attila@ritek.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Multi ordered select and indexing
Date: Thu, 29 Apr 2004 15:34:13 -0400
Message-ID: <14669.1083267253@sss.pgh.pa.us> (raw)
In-Reply-To: <000001c42937$637db7a0$0b02010a@atesz>
References: <000001c42937$637db7a0$0b02010a@atesz>

"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



view thread (6+ messages)

Message-ID: <14669.1083267253@sss.pgh.pa.us>
Permalink:  ../14669.1083267253@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14669.1083267253@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, antal.attila@ritek.hu
  Subject: Re: Multi ordered select and indexing
  In-Reply-To: <14669.1083267253@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox