Re: Regexp match not working.. (SQL help)

From: Phoenix Kiula <phoenix(dot)kiula(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Regexp match not working.. (SQL help)
Date: 2011-05-12 14:15:48
Message-ID: BANLkTiknqPHawWg6xmuiZV=Jp=mMLTm_8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 11, 2011 at 11:18 PM, Phoenix Kiula <phoenix(dot)kiula(at)gmail(dot)com> wrote:
> I have a text column in a table, which I want to search through --
> seeking the occurrence of about 300 small strings in it.
>
> Let's say the table is like this:
>
>    table1 (
>         id   bigint primary key
>        ,mytext   text
>        ,mydate  timestamp without time zone
>    );
>
>
> I am using this SQL:
>
>   SELECT id FROM table1
>   WHERE   mytext   ~*   E'sub1|sub2|sub3|sub4...'
>   LIMIT 10;
>
> This is basically working, but some of the "mytext" columns being
> returned that do not contain any of these substrings. Am I doing the
> POSIX regexp wrongly? This same thing works when I try it in PHP with
> preg_match. But not in Postgresql. I have tried several variations
> too:
>
>   WHERE   mytext   ~*   E'(sub1)(sub2)(sub3)(sub4)...'
>
>  None of this is working. I cannot seem to get out the results that do
> NOT contain any of those strings.
>
> Appreciate any pointers!
>
> Thanks!
>

My bad. I figured out that the pipe should only separate the strings
to be searched. I had one stray pipe at the end:

SELECT id FROM table1
WHERE mytext ~* E'sub1|sub2|sub3|....subXY|'
LIMIT 10;

This meant that it was matching, well basically anything.

Sorry.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Phoenix Kiula 2011-05-12 14:23:38 Massive delete from a live production DB
Previous Message Andreas Laggner 2011-05-12 14:11:37 Re: vacuumdb with cronjob needs password since 9.0? SOLVED