Re: Regexp matching + typecasts

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ilya Ivanov <forn(at)ngs(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Regexp matching + typecasts
Date: 2014-03-24 13:47:22
Message-ID: 12065.1395668842@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ilya Ivanov <forn(at)ngs(dot)ru> writes:
> I need to find all active (status=0) items not belonging to any active
> trigger. The best I could come up with is this:

> select count(itemid) from items where status='0' and itemid not in (select
> cast(regexp_matches(expression,'{([^}]+)}','g') as integer) from triggers
> where status='0');

> However, the cast doesn't work:
> ERROR: cannot cast type text[] to integer

Well, yeah. You need to convert the possibly-multiple match results into
a set. Try putting unnest() around the regexp_matches call.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2014-03-24 13:58:31 Re: Dead rows not getting removed during vacuum
Previous Message Eduardo Morras 2014-03-24 09:00:54 Re: Upgrading from 9.2 to 9.3 causes performance degradation