Re: Regular Expressions

Lists: pgsql-sql
From: "Ezequias R(dot) da Rocha" <ezequias(at)fastcon(dot)com(dot)br>
To: pgsql-sql(at)postgresql(dot)org
Subject: Regular Expressions
Date: 2007-03-21 14:04:57
Message-ID: 46013B89.4040603@fastcon.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hi list,

I would like to know if postgresql has a Regular Expressions (Regex)
implemented already.

With it we could implement queries like

Select * from myClientes where name = 'E[zs]equias'

where the result occurs even if the field has Ezequias or Esequias.

Regards
Ezequias


From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: "Ezequias R(dot) da Rocha" <ezequias(at)fastcon(dot)com(dot)br>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-21 14:28:59
Message-ID: 4601412B.4090500@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Ezequias R. da Rocha wrote:
> Hi list,
>
> I would like to know if postgresql has a Regular Expressions (Regex)
> implemented already.
>
> With it we could implement queries like
>
> Select * from myClientes where name = 'E[zs]equias'
>
> where the result occurs even if the field has Ezequias or Esequias.
>
> Regards
> Ezequias

Pretty easy to find matches in the documentation at
http://search.postgresql.org/

eg.
http://www.postgresql.org/docs/8.2/interactive/functions-matching.html


From: Guy Fraser <guy(at)incentre(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-21 14:36:46
Message-ID: 1174487806.26600.15.camel@sigurd.incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Wed, 2007-03-21 at 11:04 -0300, Ezequias R. da Rocha wrote:
> Hi list,
>
> I would like to know if postgresql has a Regular Expressions (Regex)
> implemented already.
>
> With it we could implement queries like
>
> Select * from myClientes where name = 'E[zs]equias'
>
Case Sensitive Regular Match ~
Case Insensitive Regular Match ~*
Negated Case Sensitive Regular Match !~
Negated Case Insensitive Regular Match !~*

Select * from myClientes where name ~ 'E[zs]equias'

> where the result occurs even if the field has Ezequias or Esequias.
>
> Regards
> Ezequias
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
--
Guy Fraser
Network Administrator
The Internet Centre
1-888-450-6787
(780)450-6787


From: "Ezequias R(dot) da Rocha" <ezequias(at)fastcon(dot)com(dot)br>
To: Guy Fraser <guy(at)incentre(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-21 17:37:07
Message-ID: 46016D43.9030300@fastcon.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Guy Fraser escreveu:
> On Wed, 2007-03-21 at 11:04 -0300, Ezequias R. da Rocha wrote:
>
>> Hi list,
>>
>> I would like to know if postgresql has a Regular Expressions (Regex)
>> implemented already.
>>
>> With it we could implement queries like
>>
>> Select * from myClientes where name = 'E[zs]equias'
>>
>>
> Case Sensitive Regular Match ~
> Case Insensitive Regular Match ~*
> Negated Case Sensitive Regular Match !~
> Negated Case Insensitive Regular Match !~*
>
> Select * from myClientes where name ~ 'E[zs]equias'
>
>
>> where the result occurs even if the field has Ezequias or Esequias.
>>
>> Regards
>> Ezequias
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 2: Don't 'kill -9' the postmaster
>>
>>
Great I am thinking of putting my like to rest. I felt it faster than
"like" statement, have you any information about that ?

Ezequias


From: Guy Fraser <guy(at)incentre(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-21 20:32:26
Message-ID: 1174509146.26600.39.camel@sigurd.incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Wed, 2007-03-21 at 14:37 -0300, Ezequias R. da Rocha wrote:
> Guy Fraser escreveu:
> > On Wed, 2007-03-21 at 11:04 -0300, Ezequias R. da Rocha wrote:
> >
> >> Hi list,
> >>
> >> I would like to know if postgresql has a Regular Expressions (Regex)
> >> implemented already.
> >>
> >> With it we could implement queries like
> >>
> >> Select * from myClientes where name = 'E[zs]equias'
> >>
> >>
> > Case Sensitive Regular Match ~
> > Case Insensitive Regular Match ~*
> > Negated Case Sensitive Regular Match !~
> > Negated Case Insensitive Regular Match !~*
> >
> > Select * from myClientes where name ~ 'E[zs]equias'
> >
> >
> >> where the result occurs even if the field has Ezequias or Esequias.
> >>
> >> Regards
> >> Ezequias
> >>
> >> ---------------------------(end of broadcast)---------------------------
> >> TIP 2: Don't 'kill -9' the postmaster
> >>
> >>
> Great I am thinking of putting my like to rest. I felt it faster than
> "like" statement, have you any information about that ?
>

No I don't know if regular expressions are faster than "LIKE" but
I think they are more flexible. When developing queries, I usually
try different methods of matching to find out what works best for
each circumstance. Some times upper() lower() and substr() with an
"=" are more effective than other methods.

One of the more powerful features of PostgreSQL is the ability to
use sub-selects to reduce the time required to process a subset of
data from a larger volume of data.

Example :

select
*
from (
select
ss_time,
ss_date,
ss_type,
ss_data
from
full_set
where
ss_type in ('type_a','type_x')
) as sub_set
where
upper(ss_data) ~ '[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]'
order by
ss_time,
ss_date,
ss_type
;

> Ezequias
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
>


From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-22 01:35:28
Message-ID: 20070322013528.GC29677@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Wed, Mar 21, 2007 at 02:37:07PM -0300, Ezequias R. da Rocha wrote:
> Great I am thinking of putting my like to rest. I felt it faster than
> "like" statement, have you any information about that ?

I think this rather depends on what you're doing.

If you're searching for "like 'blahblah%' or " ~ 'blahblah.*'",
they're AFAIK about the same. When you have a more complicated RE,
though, it might turn out to be a win.

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
Information security isn't a technological problem. It's an economics
problem.
--Bruce Schneier


From: <ezequias(at)fastcon(dot)com(dot)br>
To: Guy Fraser <guy(at)incentre(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-27 20:01:50
Message-ID: web-47508192@correio2.docasdoporto.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Guy,

Could you give me a hand ?

I have a ZipCode table and my address table

I just would like to find out all matches that my zipcode table has where my
address table appears like this:

Elmo Street, 30

I would like my SQL find out all matches we can find 'Elmo', 'Street'.

The commas, spaces and numbers could be forgive.

I hope you could help me

Regards

Ezequias

Em Wed, 21 Mar 2007 14:32:26 -0600
Guy Fraser <guy(at)incentre(dot)net> escreveu:
>On Wed, 2007-03-21 at 14:37 -0300, Ezequias R. da Rocha wrote:
>> Guy Fraser escreveu:
>> > On Wed, 2007-03-21 at 11:04 -0300, Ezequias R. da Rocha wrote:
>> >
>> >> Hi list,
>> >>
>> >> I would like to know if postgresql has a Regular Expressions (Regex)
>> >> implemented already.
>> >>
>> >> With it we could implement queries like
>> >>
>> >> Select * from myClientes where name = 'E[zs]equias'
>> >>
>> >>
>> > Case Sensitive Regular Match ~
>> > Case Insensitive Regular Match ~*
>> > Negated Case Sensitive Regular Match !~
>> > Negated Case Insensitive Regular Match !~*
>> >
>> > Select * from myClientes where name ~ 'E[zs]equias'
>> >
>> >
>> >> where the result occurs even if the field has Ezequias or Esequias.
>> >>
>> >> Regards
>> >> Ezequias
>> >>
>> >> ---------------------------(end of broadcast)---------------------------
>> >> TIP 2: Don't 'kill -9' the postmaster
>> >>
>> >>
>> Great I am thinking of putting my like to rest. I felt it faster than
>> "like" statement, have you any information about that ?
>>
>
>No I don't know if regular expressions are faster than "LIKE" but
>I think they are more flexible. When developing queries, I usually
>try different methods of matching to find out what works best for
>each circumstance. Some times upper() lower() and substr() with an
>"=" are more effective than other methods.
>
>One of the more powerful features of PostgreSQL is the ability to
>use sub-selects to reduce the time required to process a subset of
>data from a larger volume of data.
>
>Example :
>
>select
> *
>from (
> select
> ss_time,
> ss_date,
> ss_type,
> ss_data
> from
> full_set
> where
> ss_type in ('type_a','type_x')
> ) as sub_set
>where
> upper(ss_data) ~ '[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]'
>order by
> ss_time,
> ss_date,
> ss_type
>;
>
>
>> Ezequias
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 7: You can help support the PostgreSQL project by donating at
>>
>> http://www.postgresql.org/about/donate
>>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate

--
Ezequias Rodrigues da Rocha


From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: ezequias(at)fastcon(dot)com(dot)br, Guy Fraser <guy(at)incentre(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions
Date: 2007-03-27 22:16:10
Message-ID: 150597.94573.qm@web31808.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

> Could you give me a hand ?
>
> I have a ZipCode table and my address table
>
> I just would like to find out all matches that my zipcode table has where my
> address table appears like this:
>
> Elmo Street, 30
>
> I would like my SQL find out all matches we can find 'Elmo', 'Street'.
>

select zipcode
from zipzodetable
where address ~ 'Elmo'
and address ~ 'Street';

If the query is too slow I expect that installing the tsearch2 contrib module and using the
tsearch2 type queries would give you want you wanted but in a fraction of the time.

Regards,
Richard Broersma Jr.


From: <ezequias(at)fastcon(dot)com(dot)br>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>,pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions [progress]
Date: 2007-03-28 12:25:41
Message-ID: web-47565318@correio2.docasdoporto.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Richards and List,

Now I find out the 'similar to' statement where I can do such search, but I
must still parse all substrings.

Here is my stage:

Select * from myAddressTable where address similar to ('%(ELMO|ST.|258)%')

But I still need to Separete all strings.

Could someone help me in this crusade ?

Regards
Ezequias

Em Tue, 27 Mar 2007 15:16:10 -0700 (PDT)
Richard Broersma Jr <rabroersma(at)yahoo(dot)com> escreveu:
>> Could you give me a hand ?
>>
>> I have a ZipCode table and my address table
>>
>> I just would like to find out all matches that my zipcode table has where my
>> address table appears like this:
>>
>> Elmo Street, 30
>>
>> I would like my SQL find out all matches we can find 'Elmo', 'Street'.
>>
>
>select zipcode
>from zipzodetable
>where address ~ 'Elmo'
>and address ~ 'Street';
>
>If the query is too slow I expect that installing the tsearch2 contrib module
>and using the
>tsearch2 type queries would give you want you wanted but in a fraction of the
>time.
>
>Regards,
>Richard Broersma Jr.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: explain analyze is your friend

--
Ezequias Rodrigues da Rocha


From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: ezequias(at)fastcon(dot)com(dot)br, pgsql-sql(at)postgresql(dot)org
Subject: Re: Regular Expressions [progress]
Date: 2007-03-28 14:10:26
Message-ID: 540160.27049.qm@web31804.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql


> Select * from myAddressTable where address similar to ('%(ELMO|ST.|258)%')
>
> But I still need to Separete all strings.

What is it that you are trying to achieve? What string would you like to seperate?
Regards,
Richard Broersma Jr.