Thread: lower function

lower function

From
Mage
Date:
       Hello,


I have a database with encoding latin2, ctype hu_HU, posgresql 8.0.1.
Keyword split is a plperl function:

create or replace function keywords_split(text) returns text as $$
  my $text = lc $_[0];
    return $text;
$$
language plperl;

My problem is:

$ psql teszt;
Welcome to psql 8.0.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

teszt=# select lower('úéöÖÉÁ');
 lower
--------
 úéööéá
(1 row)

teszt=# select keywords_split('AúéöÖÉÁ');
 keywords_split
----------------
 aúéöÖÉÁ
(1 row)

teszt=# select lower('úéöÖÉÁ');
 lower
--------
 úéöÖÉÁ
(1 row)


       Mage



Re: lower function

From
"Daniel Verite"
Date:
 Mage wrote:

> teszt=# select keywords_split('AúéöÖÉÁ');
>  keywords_split
> ----------------
>  aúéöÖÉÁ
> (1 row)

What happens if you add
  use locale;
in your perl function before calling lc ?

--
 Daniel
 PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


Re: lower function

From
Mage
Date:
Daniel Verite wrote:

> Mage wrote:
>
>
>
>>teszt=# select keywords_split('AúéöÖÉÁ');
>> keywords_split
>>----------------
>> aúéöÖÉÁ
>>(1 row)
>>
>>
>
>What happens if you add
>  use locale;
>in your perl function before calling lc ?
>
>
with use locale;:

select keywords_split('AúéöÖÉÁ');
ERROR:  creation of Perl function failed: 'require' trapped by operation
mask at (eval 6) line 2.

Another problem:

create or replace function keywords_split(text) returns text as $$
    my $res = spi_exec_query("select lower('" . $_[0] . "')");
    my $text = 'test' . $res->{rows}[0]->{lower};
    return $text;
$$
language plperl;

# select keywords_split('AúéöÖÉÁ');
 keywords_split
----------------
 testaúéöÖÉÁ
(1 row)

The spi_exec_query with lower also don't work.

I have found another bug in a plperl trigger which I can't reproduce. I
find plperl a bit buggy.

       Mage


Re: lower function

From
"Daniel Verite"
Date:
 Mage wrote:

> with use locale;:
>
> select keywords_split('AúéöÖÉÁ');
> ERROR:  creation of Perl function failed: 'require' trapped by operation
> mask at (eval 6) line 2.

Ah. So maybe it would work with plperlu instead of plperl.

--
 Daniel
 PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


Re: lower function

From
Mage
Date:
Daniel Verite wrote:

> Mage wrote:
>
>
>
>>with use locale;:
>>
>>select keywords_split('AúéöÖÉÁ');
>>ERROR:  creation of Perl function failed: 'require' trapped by operation
>>mask at (eval 6) line 2.
>>
>>
>
>Ah. So maybe it would work with plperlu instead of plperl.
>
>
I did, and it didn't help.

       Mage

Re: lower function

From
Mage
Date:
It's serious.

teszt=# select lower('AúéöÖÉÁ');
  lower
---------
 aúéööéá
(1 row)

teszt=# create or replace function keywords_split(text) returns text as $$
teszt$# return '';
teszt$# $$
teszt-# language plperlu;
CREATE FUNCTION
teszt=# select keywords_split('');
 keywords_split
----------------

(1 row)

teszt=# select lower('AúéöÖÉÁ');
  lower
---------
 aúéöÖÉÁ
(1 row)


          Mage


Re: lower function

From
Tom Lane
Date:
Mage <mage@mage.hu> writes:
> It's serious.

That's a Perl bug not a Postgres bug: libperl should not change the
process's locale settings, or at least if it does it should restore
the prior settings before returning.  It doesn't.

            regards, tom lane

Re: lower function

From
Mage
Date:
Tom Lane wrote:

>Mage <mage@mage.hu> writes:
>
>
>>It's serious.
>>
>>
>
>That's a Perl bug not a Postgres bug: libperl should not change the
>process's locale settings, or at least if it does it should restore
>the prior settings before returning.  It doesn't.
>
>
>
I checked with show all, client and server encoding remained latin2, and
lc_ctype remained hu_HU. However, the lower function got corrupted
(encoding) until the end of the session.

I can reproduce the bug on an Debian Sarge and on a Gentoo. Both are
up-to-date.

What should I do? Subscribe to perl list and tell about this? I have to
write a trigger which can't be written well in plpgsql. My options are
to learn python or tcl on basic level in one day. I am not sure I want
and can do this.

       Mage



Re: lower function

From
Scott Marlowe
Date:
On Wed, 2005-04-06 at 17:26, Mage wrote:
> Tom Lane wrote:
>
> >Mage <mage@mage.hu> writes:
> >
> >
> >>It's serious.
> >>
> >>
> >
> >That's a Perl bug not a Postgres bug: libperl should not change the
> >process's locale settings, or at least if it does it should restore
> >the prior settings before returning.  It doesn't.
> >
> >
> >
> I checked with show all, client and server encoding remained latin2, and
> lc_ctype remained hu_HU. However, the lower function got corrupted
> (encoding) until the end of the session.
>
> I can reproduce the bug on an Debian Sarge and on a Gentoo. Both are
> up-to-date.
>
> What should I do? Subscribe to perl list and tell about this? I have to
> write a trigger which can't be written well in plpgsql. My options are
> to learn python or tcl on basic level in one day. I am not sure I want
> and can do this.

You're far more likely to learn tcl or python or php in an afternoon
than to get a patched perl executable in that time.

But I'd still report the bug to them.

Re: lower function

From
Mage
Date:
Scott Marlowe wrote:

>
>You're far more likely to learn tcl or python or php in an afternoon
>than to get a patched perl executable in that time.
>
>But I'd still report the bug to them.
>
>
create or replace function keywords_split(text) returns text as $$
    use locale;
    use POSIX qw(locale_h);
    setlocale(LC_CTYPE,'hu_HU');
    return '';
$$
language plperlu;

It works. And it's so nasty. I have to insert these into every plperl
function.
I am not subscribed to any perl list. Would someone report this bug?

       Mage