Re: How to create index on only some of the rows

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to create index on only some of the rows
Date: 2011-02-15 00:47:29
Message-ID: ijcif1$grl$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2011-02-07, A B <gentosaker(at)gmail(dot)com> wrote:
> Hello.
>
> How do you create an index for only some of the rows in a table? I
> read in the docs:
>
> "The expression used in the WHERE clause can refer only to columns of
> the underlying table, but it can use all columns, not just the ones
> being indexed. Presently, subqueries and aggregate expressions are
> also forbidden in WHERE. The same restrictions apply to index fields
> that are expressions. "
>
> So until this changes, can you just add a boolean field to tell if the
> column should be used in the index, and then run "create index ....
> where use_in_index = true" or are there other (better?) ways of doing
> this?

the manual section quoted above is not exactly correct,
you are also allowed constants, immutable functions and operators.

create index foo_bigbar on foo(bar) where quux > 8.6;
create index foo_bar_nofred on foo(bar) where fred is null;

etc...

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-02-15 01:47:27 Re: Alter Default Privileges Does Not Work For Functions
Previous Message Derrick Rice 2011-02-15 00:13:51 Speeding up index scans by truncating timestamp?