Re: matching column of regexps

From: Vik Fearing <vik(dot)fearing(at)dalibo(dot)com>
To: James Cloos <cloos(at)jhcloos(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: matching column of regexps
Date: 2014-05-19 00:35:02
Message-ID: 537951B6.4070202@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 05/18/2014 07:44 PM, James Cloos wrote:
> Is there a better way to answer the question, "Do ANY rows match?"
> without having to return the list of matching rows? I didn't find
> anything googling.

select exists (select 1 from retest where active is true and ? ~ re);

> Is there a way to index such a table/query?

There are several ways to index such a query. If there are very many
rows but with only a few being active, then a partial index will do wonders.

http://www.postgresql.org/docs/current/static/indexes-partial.html

Otherwise, it is possible to use an index for regular expressions using
the pg_trgm extension.

http://www.postgresql.org/docs/current/static/pgtrgm.html

--
Vik

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message James Cloos 2014-05-19 05:43:33 Re: matching column of regexps
Previous Message James Cloos 2014-05-18 23:44:19 matching column of regexps