Re: Queries with Regular Expressions

From: "Silas Justiniano" <silasju(at)gmail(dot)com>
To: "PostgreSQL-general general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Queries with Regular Expressions
Date: 2006-04-06 20:52:39
Message-ID: 58e3b9040604061352j55fd413cv8408f5ad0a809a65@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John, it worked completely fine! Thank you! I don't understand exactly
the difference between [] and () for REs, but I'm starting to study
them deeply.

Thank you very much! Pg is great!

On 4/6/06, John D. Burger <john(at)mitre(dot)org> wrote:
> > But I just can't make it work correctly using brackets:
> > SELECT field FROM table WHERE field ~* 'ch[aã]o';
> >
> > It just returns tuples that have 'chao', but not 'chão'.
> >
> > My queries are utf-8 an the database is SQL_ASCII.
>
> I suspect the bracketed expression is turning into [aXY], where XY is
> the two-byte sequence corresponding to ã in UTF8. So the regular
> expression is only going to match strings of the form chao, chXo and
> chYo. To make sure that this is what's happening, try this:
>
> select length('ã');
>
> I bet you get back 2, not 1. I don't know if a UTF8 database will
> handle this correctly or not. The safest thing to do may be to use
> queries like this:
>
> SELECT field FROM table WHERE field ~* 'ch(a|ã)o';
>
> - John D. Burger
> MITRE
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--
Silas Justiniano - Brazil

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2006-04-06 20:55:50 Re: Not able to install PostgreSQL in my machine
Previous Message Jim Nasby 2006-04-06 20:52:34 Re: PostgreSQL support on Redhat Advance Server 2.1