Re: different sort order for primary key index

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Paul Hartley *EXTERN*" <phartley(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: different sort order for primary key index
Date: 2009-10-14 12:58:18
Message-ID: D960CB61B694CF459DCFB4B0128514C203937F8C@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Paul Hartley wrote:
> I have a composite primary key for a table, let's call it
> (col1, col2). When this table is created, obviously an
> implicit index is created for this key. I would like the
> sort order of this index to be different for the two columns
> -- if I were to create the index myself, I would pass on
> (col1, col2 DESC). The ALTER INDEX documentation suggests
> that it's not possible to change the sort order of a column,
> so I can envision two ways to get around this: 1) create a
> second UNIQUE index of (col1, col2 DESC), or 2) not define a
> primary key and just specify a UNIQUE index separately.
> Primary keys are basically restricted to being unique and
> non-null, but I'm unclear if PostgreSQL treats primary keys
> differently from unique, non-null constraints.

I think you can safely go for 2).
Although I admit it is not pretty.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Grzegorz Jaśkiewicz 2009-10-14 13:16:30 Re: different sort order for primary key index
Previous Message Craig Ringer 2009-10-14 11:11:23 Re: Cannot start the postgres service