Re: not like perl..

From: "A(dot)M(dot)" <agentm(at)themactionfaction(dot)com>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Cc: hook <hook(at)lota(dot)us>
Subject: Re: not like perl..
Date: 2011-03-29 15:29:16
Message-ID: 15CDED40-E69B-47F6-88F7-EF0220E8D06A@themactionfaction.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mar 29, 2011, at 10:18 AM, hook wrote:

> I have a simple table with a varchar(32) field that I am trying to extract data using regular expressions.
>
> select * from spam where inetaddr like '100.%'
> row | inetaddr | tdate ------+--------------+---------------------------
> 3245 | 100.81.98.51 | 03/08/2011 07:21:19.29209 -----works fine
>
>
> select * from spam where inetaddr like E'\d\d\d.%'
> row | inetaddr | tdate
> -----+----------+-------
> (0 rows) --- zip ???????????
>
> slect * from spam where inetaddr like E'\d.%'
> row | inetaddr | tdate -------+--------------------------------+----------------------------
> 49424 | d(dot)russell_ul(at)jdmarketing(dot)co(dot)uk | 03/27/2011 15:46:41.110566 ??????????? though \d was a digit match????
>
>
> select * from spam where inetaddr like E'\\d.%'
> row | inetaddr | tdate -------+--------------------------------+----------------------------
> 49424 | d(dot)russell_ul(at)jdmarketing(dot)co(dot)uk | 03/27/2011 15:46:41.110566 ???????????
>
>
> What am I doing wrong???

You are not using the regular expression operator.

test=# create table test(a text);
CREATE TABLE
test=# insert into test(a) values ('100.81.98.51');
INSERT 0 1
test=# select * from test where a ~ $$^\d+\.$$;
a
--------------
100.81.98.51
(1 row)

This is just like perl.

Cheers,
M

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-03-29 15:31:26 Re: Date conversion using day of week
Previous Message Marc Munro 2011-03-29 15:07:48 Date conversion using day of week