[Pljava-dev] calling pljava function seems to change locale settings

From: imre at auul(dot)pri(dot)ee (Imre Oolberg)
To:
Subject: [Pljava-dev] calling pljava function seems to change locale settings
Date: 2008-11-23 18:07:27
Message-ID: 49299BDF.9080607@auul.pri.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hallo!

First of all i must confess i am not experienced java user but people
trusted to me maintaining PostgreSQL + PL/Java environment on Solaris 10
Sparc.

We use PostgreSQL 8.3.5 and PL/Java 1.4.0 compiled with GCC from
www.blastwave.org i.e. CSW repostitory and generally thing work as expected.

Now we have a bit strange problem which manifests in certain locale
parameters getting changed after calling PL/Java function from plpgsql
function. I am really not sure it has do to with PL/Java itself but at
the moment it seems so.

I describe my testing and what result i have got.

PG startup skript sets two locale env. variables

export LC_CTYPE=et_EE.UTF-8
export LC_COLLATE=et_EE.UTF-8
export LC_NUMERIC=C

and postgresql.conf has

lc_messages = 'et_EE.UTF-8' # locale for system error message
lc_monetary = 'et_EE.UTF-8' # locale for monetary formatting
lc_numeric = 'C' # locale for number formatting
lc_time = 'et_EE.UTF-8' # locale for time formatting

I have java class helloworld.java essentially compiled from

package com.mycompany.helloworld;

public class HelloWorld {

public static String helloWorld() {
return "Hello World";
}
}

and what i loaded into database

CREATE OR REPLACE FUNCTION helloworld()
RETURNS "varchar" AS
'com.mycompany.helloworld.HelloWorld.helloWorld'
LANGUAGE 'java' VOLATILE;

and after saying it gives

$ psql -U postgres -h localhost -c 'select * from helloworld();' db

helloworld
-----------------
Hello World
(1 row)

And i call it from plpgsql function like this

DECLARE
txt varchar;
BEGIN
perform sqlj.print_locale();
perform helloworld();
perform sqlj.print_locale();
txt:='test function';
return txt;
END;

where sqlj.print_locale() is plperlu function assisting to print locale
parameters before and after calling helloworld() and contains

use POSIX qw(locale_h);

open (fh, '>>/tmp/locale.log');
print fh "start\n";
$lokaat{LC_CTYPE}=setlocale(LC_CTYPE);
$lokaat{LC_TIME}=setlocale(LC_TIME);
$lokaat{LC_COLLATE}=setlocale(LC_COLLATE);
$lokaat{LC_MESSAGES}=setlocale(LC_MESSAGES);
$lokaat{LC_MONETARY}=setlocale(LC_MONETARY);
$lokaat{LC_NUMERIC}=setlocale(LC_NUMERIC);

while ( my ($key, $value) = each(%lokaat) ) {
print fh "$key => $value\n";
}
print fh "end\n";
close fh;

return "i am print_locale";

And the result is

beginning
LC_CTYPE => et_EE.UTF-8
LC_NUMERIC => C
LC_MONETARY => C
LC_TIME => C
LC_MESSAGES => et_EE.UTF-8
LC_COLLATE => et_EE.UTF-8
end
beginning
LC_CTYPE => et_EE.UTF-8
LC_NUMERIC => et_EE.UTF-8
LC_MONETARY => et_EE.UTF-8
LC_TIME => et_EE.UTF-8
LC_MESSAGES => et_EE.UTF-8
LC_COLLATE => et_EE.UTF-8
end

I also tried to call from plpgsql plperlu function but in that case
locale parameters remained the same.

If somebody suggests what to investigate further or to change to
accomplish that these variables (esp. LC_NUMERIC) stay unchanged i would
be very grateful.

Best regards,

Imre

Browse pljava-dev by date

  From Date Subject
Next Message Eric BOYER 2008-11-24 16:06:51 [Pljava-dev] problem with date and timezone
Previous Message Kris Jurka 2008-10-23 19:52:13 [Pljava-dev] pljava concurrency