Re: pattern matching indexing

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: pattern matching indexing
Date: 2012-12-27 13:34:19
Message-ID: 1356615259.13340.4.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Mon, 2012-12-24 at 10:12 -0500, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > To index pattern matching, you can use the _pattern_ops operator
> > classes, or you can set the column collation in the index to "C". The
> > latter option doesn't appear to be documented (unless you read very deep
> > between the lines). Is that intentional?
>
> It is stated at
> http://www.postgresql.org/docs/devel/static/indexes-opclass.html
> that you don't need the special pattern opclasses in C locale.
> Feel free to rephrase or document elsewhere if you find that too
> obscure.

What it doesn't make very clear is that you can also override the locale
in the index definition itself. So instead of the recommended

CREATE INDEX test_index ON test_table (col varchar_pattern_ops);

you can write nearly equivalently

CREATE INDEX test_index ON test_table (col COLLATE "C");

I'm also wondering whether the latter wouldn't be a preferable
recommendation going forward. I suppose it's also a matter of taste,
but such an index can also be used for other things (e.g. ORDER BY col
COLLATE "C"), and it uses less obscure and magic functionality.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2012-12-27 16:39:30 Re: pattern matching indexing
Previous Message Fujii Masao 2012-12-25 16:52:20 Re: pg_resetxlog -l