Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBOKv-0006fi-HE for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jun 2023 23:31:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBOKu-0007I9-FP for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jun 2023 23:31:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBOKu-0007I0-2c for pgsql-hackers@lists.postgresql.org; Mon, 19 Jun 2023 23:31:04 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qBOKq-0038bz-Aj for pgsql-hackers@postgreSQL.org; Mon, 19 Jun 2023 23:31:02 +0000 Received: from [192.168.243.196] (mobile-access-5d6a03-188.dhcp.inet.fi [93.106.3.188]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4QlQxS5jX0zyRq; Tue, 20 Jun 2023 02:30:52 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1687217455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EflZqa3PdntzvmGKGO320gsUyjAzo/IlnMIDsQq92U=; b=tidzWeARp8cp/658JDuBofxO29VQi1nrFekHEA58SgRq1EedhiBTDd/3rn0KSFi4XE89X+ BrVp0HtM0ip9OrNLUz0eEjmp3jjbuCAOq9dYbwhkXp4MMAO/bZij5BdV8dkYc/HGn7zg+V z21YGyvtHdvoVJaocmeGB7+N2snKqN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1687217455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EflZqa3PdntzvmGKGO320gsUyjAzo/IlnMIDsQq92U=; b=MlOVCcPthqaOkZoPG8tbNj2ihKUfkeWkE97b9sFjwaAcm35gqPufu78tF4u0vmohUnIveR 5aVPrfpPgQ/oQjAdkqNe6KmwWPRUor7GzBN21A6dZiPwhtR6Do6hpKbdJLk9rxSCCxI4n6 O7Kj5PbQlVXCyMOPFcV8Krq08wCC9Zo= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1687217455; a=rsa-sha256; cv=none; b=LiMyrU4+DWXBTwTNbJbobQR8Ovu0VjCFNSPiqEkjQQ3PedH2lcPr4JuGGd1G64BfdZpFV7 JZi4kjJVpyrLLcyq8yz/N8w6U4IiK1pe9cRuLJW5RH/JCLPhq9MK8+xCeF1Jcmb4ynO3l/ UrmHOh/UWMiSUeamuNjmE9PHcM2vNdk= Message-ID: Date: Tue, 20 Jun 2023 02:30:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG Content-Language: en-US To: Joe Conway Cc: Tristan Partin , gdo@leader.it, Tom Lane , PostgreSQL-development References: <17946-3e84cb577e9551c3@postgresql.org> <1564676.1685043220@sss.pgh.pa.us> <555bb26e-c27c-ab65-028f-3fd5b82df9de@iki.fi> <5676b739-0854-f924-4b97-466e3504c692@joeconway.com> <665279.1686422574@sss.pgh.pa.us> <574a1afa-5c6e-829c-0fed-a9ff44719f9f@joeconway.com> <49dfcad8-90fa-8577-008f-d142e61af46b@iki.fi> <41a4898e-1cdb-960d-f17e-d71886407e04@joeconway.com> <18c6979a-126a-e530-7cc4-3b6984b1997b@joeconway.com> From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18/06/2023 21:27, Joe Conway wrote: > I have proposed a targeted fix that I believe is safe to backpatch -- > attached. > > IIUC, Tom was +1, but Heikki was looking for a more general solution. > > My issue with the more general solution is that it will likely be too > invasive to backpatch, and at the moment at least, there are no other > confirmed bugs related to all of this (even if the current code is more > fragile than we would prefer). Ok, I agree switching to uselocale() everywhere is too much to backpatch. We should consider it for master though. With the patch you're proposing, do we now have a coding rule that you must call "uselocale(LC_GLOBAL_LOCALE)" before every and any call to setlocale()? If so, you missed a few spots: pg_perm_setlocale, pg_bind_textdomain_codeset, and cache_locale_time. The current locale affects a lot of other things than localeconv() calls. For example, LC_MESSAGES affects all strerror() calls. Do we need to call "uselocale(LC_GLOBAL_LOCALE)" before all possible strerror() calls too? I think we should call "uselocale(LC_GLOBAL_LOCALE)" immediately after returning from the perl interpreter, instead of before setlocale() calls, if we want all Postgres code to run with the global locale. Not sure how much performance overhead that would have. I just found out about perl's "switch_to_global_locale" function (https://perldoc.perl.org/perlapi#switch_to_global_locale). Should we use that? Testing the patch, I bumped into this: postgres=# create or replace function finnish_to_number() returns numeric as $$ select to_number('1,23', '9D99'); $$ language sql set lc_numeric to 'fi_FI.utf8'; CREATE FUNCTION postgres=# DO LANGUAGE 'plperlu' $$ use POSIX qw(setlocale LC_NUMERIC); use locale; setlocale LC_NUMERIC, "fi_FI.utf8"; $n = 5/2; # Assign numeric 2.5 to $n spi_exec_query('SELECT finnish_to_number()'); $a = " $n"; # Locale-dependent conversion to string elog(NOTICE, "half five is $n"); # Locale-dependent output $$; NOTICE: half five is 2,5 DO postgres=# select to_char(now(), 'Day'); WARNING: could not determine encoding for locale "en_GB.UTF-8": codeset is "ANSI_X3.4-1968" to_char ----------- Tuesday (1 row) -- Heikki Linnakangas Neon (https://neon.tech)