Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)atentus(dot)com>
Cc: Timur <itvthor(at)sdf(dot)lonestar(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)
Date: 2002-08-25 15:02:01
Message-ID: 5805.1030287721@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera <alvherre(at)atentus(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2002-08-25 15:07:39 Re: CREATE INDEX .. ON table1 (field1 asc, field2 desc)
Previous Message Bruce Momjian 2002-08-25 14:34:29 Re: [GENERAL] PostgreSQL 7.2.2: Security Release