Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc) - Mailing list pgsql-general

From Tom Lane
Subject Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)
Date
Msg-id 5805.1030287721@sss.pgh.pa.us
Whole thread Raw
In response to Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)  (Alvaro Herrera <alvherre@atentus.com>)
List pgsql-general
Alvaro Herrera <alvherre@atentus.com> writes:
>> I am new to PostgreSQL and databases in general, and I have this
>> question: why it is not possible to specify ordering when creating an
>> index?

> Because there is no point in doing so.  Postgres automatically scans an
> index in reverse direction if you want to use descending order.

But he wants, or says he wants, ASC order on the first column and DESC
on the second.  I concur with Martijn that this might just be a
beginner's mistake in giving the command ... but if that's really what
he wants then it doesn't correspond to either forward or reverse scan
of a normal index.  You would indeed need to make a custom opclass for
the second column in order to make an index that can be scanned in this
order.

            regards, tom lane

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)
Next
From: Michael Engelhart
Date:
Subject: mac OS X 10.2 (Jaguar) Build problems