lower function

Started by Mageabout 21 years ago10 messagesgeneral
Jump to latest
#1Mage
mage@mage.hu

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

#2Daniel Verite
daniel@manitou-mail.org
In reply to: Mage (#1)
Re: lower function

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

#3Mage
mage@mage.hu
In reply to: Daniel Verite (#2)
Re: lower function

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

#4Daniel Verite
daniel@manitou-mail.org
In reply to: Mage (#3)
Re: lower function

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

#5Mage
mage@mage.hu
In reply to: Daniel Verite (#4)
Re: lower function

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

#6Mage
mage@mage.hu
In reply to: Mage (#5)
Re: lower function

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

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Mage (#6)
Re: lower function

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

#8Mage
mage@mage.hu
In reply to: Tom Lane (#7)
Re: lower function

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

#9Scott Marlowe
smarlowe@g2switchworks.com
In reply to: Mage (#8)
Re: lower function

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.

#10Mage
mage@mage.hu
In reply to: Scott Marlowe (#9)
Re: lower function

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