Using regexp_matches in the WHERE clause

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Using regexp_matches in the WHERE clause
Date: 2012-11-26 12:13:06
Message-ID: k8vmbm$1fg$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I stumbled over this question on Stackoverflow

http://stackoverflow.com/questions/13564369/postgresql-using-column-data-as-pattern-for-regexp-match

And my initial reaction was, that this should be possible using regexp_matches.

So I tried:

SELECT *
FROM some_table
WHERE regexp_matches(somecol, 'foobar') is not null;

However that resulted in: ERROR: argument of WHERE must not return a set

Hmm, even though an array is not a set I can partly see what the problem is
(although given the really cool array implementation in PostgreSQL I was a bit surprised).

So I though, if I convert this to an integer, it should work:

SELECT *
FROM some_table
WHERE array_length(regexp_matches(somecol, 'foobar'), 1) > 0

but that still results in the same error.

But array_length() clearly returns an integer, so why does it still throw this error?

I'm using 9.2.1

Regards
Thomas

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marcin Krawczyk 2012-11-27 09:27:10 locks problem
Previous Message Marcin Krawczyk 2012-11-20 15:02:29 Re: regexp_replace behavior