agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Vik Fearing <vik.fearing@dalibo.com>
To: James Cloos <cloos@jhcloos.com>
To: pgsql-sql@postgresql.org
Subject: Re: matching column of regexps
Date: Sun, 18 May 2014 20:35:02 -0400
Message-ID: <537951B6.4070202@dalibo.com> (raw)
In-Reply-To: <m3wqdi649f.fsf@carbon.jhcloos.org>
References: <m3wqdi649f.fsf@carbon.jhcloos.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (3+ messages)  latest in thread

Message-ID: <537951B6.4070202@dalibo.com>
Permalink:  ../537951B6.4070202@dalibo.com/
Also on:    postgresql.org/message-id/537951B6.4070202@dalibo.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: vik.fearing@dalibo.com, cloos@jhcloos.com
  Subject: Re: matching column of regexps
  In-Reply-To: <537951B6.4070202@dalibo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox