Thread: locale and spanish acute

locale and spanish acute

From
Martín Marqués
Date:
I'm doing some searches with LIKE and have a problem with words with acute
vocals. I would like más to be treated the same way as mas, and vice-verse.

Is this because I don't have the locale set correctly?

Saludos... ;-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------

Re: locale and spanish acute

From
Peter Eisentraut
Date:
Martín Marqués writes:

> I'm doing some searches with LIKE and have a problem with words with acute
> vocals. I would like más to be treated the same way as mas, and vice-verse.
>
> Is this because I don't have the locale set correctly?

No, it's because it doesn't work that way.  What you probably want to do
is "accent-fold" your strings before sending them through pattern
matching.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: locale and spanish acute

From
Martín Marqués
Date:
On Mié 12 Sep 2001 20:10, you wrote:
> Martín Marqués writes:
> > I'm doing some searches with LIKE and have a problem with words with
> > acute vocals. I would like más to be treated the same way as mas, and
> > vice-verse.
> >
> > Is this because I don't have the locale set correctly?
>
> No, it's because it doesn't work that way.  What you probably want to do
> is "accent-fold" your strings before sending them through pattern
> matching.

What does "accent-fold" mean?

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------

Re: locale and spanish acute

From
Peter Eisentraut
Date:
Martín Marqués writes:

> On Mié 12 Sep 2001 20:10, you wrote:
> > Martín Marqués writes:
> > > I'm doing some searches with LIKE and have a problem with words with
> > > acute vocals. I would like más to be treated the same way as mas, and
> > > vice-verse.
> > >
> > > Is this because I don't have the locale set correctly?
> >
> > No, it's because it doesn't work that way.  What you probably want to do
> > is "accent-fold" your strings before sending them through pattern
> > matching.
>
> What does "accent-fold" mean?

Convert all accented characters to some other characters in a way that is
meaningful to you.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: locale and spanish acute

From
Martín Marqués
Date:
On Mié 12 Sep 2001 21:52, Peter Eisentraut wrote:
> Martín Marqués writes:
> >
> > What does "accent-fold" mean?
>
> Convert all accented characters to some other characters in a way that is
> meaningful to you.

OK, I think I got what you told me.
lets see... I have this query:

select count(*) from tab1 where col1 LIKE '%mas%'

but I would like it to catch rows with "más" also.

The only thing I can think of is makeing a function that applied to col1
would give me col1 but without accents. Say the function is called
no_accents, so:

no_accents(más)=mas

Now, the problem is that I have little idea on making such a function. Is it
very difficult?

Saludos... :-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------

Re: locale and spanish acute

From
Peter Eisentraut
Date:
Martín Marqués writes:

> select count(*) from tab1 where col1 LIKE '%mas%'
>
> but I would like it to catch rows with "más" also.
>
> The only thing I can think of is makeing a function that applied to col1
> would give me col1 but without accents. Say the function is called
> no_accents, so:
>
> no_accents(más)=mas
>
> Now, the problem is that I have little idea on making such a function. Is it
> very difficult?

CREATE FUNCTION no_accents(text) RETURNS text AS '
my $arg = $_[0];
$arg =~ tr/áéëíñóú/aeeinou/;
return $arg;
' LANGUAGE 'plperl';

Something similar should be possible in PL/Tcl if you prefer that.  Or you
bother with C and run a simple loop over the text string.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: locale and spanish acute

From
Tony Grant
Date:
On Fri, 2001-09-14 at 15:49, Peter Eisentraut wrote:
> Martín Marqués writes:
>
> > select count(*) from tab1 where col1 LIKE '%mas%'
> >
> > but I would like it to catch rows with "más" also.

select count(*) from tab1 where col1 ILIKE to_ascii($1)

works for me.

The variable is passed via .jsp

Cheers

Tony Grant

--
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html


Re: locale and spanish acute

From
Martín Marqués
Date:
On Lun 17 Sep 2001 04:31, Tony Grant wrote:
> On Fri, 2001-09-14 at 15:49, Peter Eisentraut wrote:
> > Martín Marqués writes:
> > > select count(*) from tab1 where col1 LIKE '%mas%'
> > >
> > > but I would like it to catch rows with "más" also.
>
> select count(*) from tab1 where col1 ILIKE to_ascii($1)
>
> works for me.

But I want it to work with más too. For that I would need to change that
query for this one:

select count(*) from tab1 where to_ascii(col1) ILIKE to_ascii($1)

Right?

Saludos... :-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------

Re: locale and spanish acute

From
Tony Grant
Date:
On Mon, 2001-09-17 at 22:49, Martín Marqués wrote:

> But I want it to work with más too. For that I would need to change that
> query for this one:
>
> select count(*) from tab1 where to_ascii(col1) ILIKE to_ascii($1)
>
> Right?

Right that will work because the content and the request is changed.

Cheers

Tony

--
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html