Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmBYX-0004uz-Cr for pgsql-sql@arkaria.postgresql.org; Mon, 19 May 2014 00:35:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WmBYW-00062b-QJ for pgsql-sql@arkaria.postgresql.org; Mon, 19 May 2014 00:35:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmBYV-00060x-5r for pgsql-sql@postgresql.org; Mon, 19 May 2014 00:35:51 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmBYS-0005DN-8M for pgsql-sql@postgresql.org; Mon, 19 May 2014 00:35:50 +0000 Received: from [192.168.0.23] (CPE7cb21b17a13b-CM7cb21b17a138.cpe.net.cable.rogers.com [99.245.245.83]) by mimolette.dalibo.net (Postfix) with ESMTPSA id 713B850808A3; Mon, 19 May 2014 02:35:13 +0200 (CEST) Message-ID: <537951B6.4070202@dalibo.com> Date: Sun, 18 May 2014 20:35:02 -0400 From: Vik Fearing User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: James Cloos , pgsql-sql@postgresql.org Subject: Re: matching column of regexps References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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