pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Aleksander Alekseev <aleksander@timescale.com>
Cc: pgsql-committers@lists.postgresql.org, Alexander Korotkov <aekorotkov@gmail.com>
Cc: Andrew Dunstan <andrew@dunslane.net>
Subject: Re: pgsql: psql: add an optional execution-count limit to \watch.
Date: Mon, 10 Apr 2023 11:09:41 -0400
Message-ID: <4076950.1681139381@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJ7c6TOFPoHVSxaQXfbm38_QN1v4qaugZW0LBTB-Gkvk2UwBQw@mail.gmail.com>
References: <E1pkTFl-001hzA-LR@gemulon.postgresql.org>
	<CAPpHfdv+10Uk6FWjsh3+ju7kHYr76LaRXbYayXmrM7FBU-=Hgg@mail.gmail.com>
	<2929174.1680876023@sss.pgh.pa.us>
	<CAPpHfdtgQVRZOwov-Ei4Rh=gQtFE8Hb9uKkO1d_XYmQ2XEXt0g@mail.gmail.com>
	<CAJ7c6TO9KpYYxoVVseWEQB5KtjWDkt8NfyAeKPcHoe2Jq+ykpw@mail.gmail.com>
	<4032363.1681134882@sss.pgh.pa.us>
	<CAJ7c6TOFPoHVSxaQXfbm38_QN1v4qaugZW0LBTB-Gkvk2UwBQw@mail.gmail.com>

Aleksander Alekseev <aleksander@timescale.com> writes:
>> Hmm, so psql is honoring the LC_NUMERIC setting in that environment,
>> but perl isn't.  For me, it appears that adding 'use locale;' to
>> the test script will fix it ... can you confirm if it's OK for you?

> Right, src/bin/psql/t/001_basic.pl has "use locale;" since cd82e5c7
> and it fails nevertheless.
> ...
> So it looks like what happens is LC_ALL overwrites LC_NUMERIC for perl
> but not for psql.

Oh, right, there already is one :-(.  After some more research,
I believe I see the problem: Utils.pm does

BEGIN
{
	# Set to untranslated messages, to be able to compare program output
	# with expected strings.
	delete $ENV{LANGUAGE};
	delete $ENV{LC_ALL};
	$ENV{LC_MESSAGES} = 'C';

Normally, with your settings, LC_ALL=en_US.UTF-8 would dominate
everything.  After removing that from the environment, the child
psql process will honor LC_NUMERIC=ru_RU.UTF-8 and expect \watch's
argument to be "0,01".  However, I bet that perl has already made
its decisions about what its internal locale is, so it still thinks
it should print "0.01".

I am betting that we need to make Utils.pm do

	setlocale(LC_ALL, "");

after the above-quoted bit, else it isn't doing what it is supposed to
if the calling script has already done "use locale;", as indeed
psql/t/001_basic.pl (and a small number of other places) do.

The attached makes check-world pass for me under these conflicting
environment settings, but it's kind of a scary change.  Thoughts?

			regards, tom lane

Attachments:

fix-TAP-test-locale-settings.patch (text/x-diff, 768B) download diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm index 878e12b15e..4c6cde8974 100644 --- a/src/test/perl/PostgreSQL/Test/Utils.pm +++ b/src/test/perl/PostgreSQL/Test/Utils.pm @@ -43,6 +43,7 @@ package PostgreSQL::Test::Utils; use strict; use warnings; +use locale; use Carp; use Config; @@ -55,6 +56,7 @@ use File::Spec; use File::stat qw(stat); use File::Temp (); use IPC::Run; +use POSIX qw(locale_h); use PostgreSQL::Test::SimpleTee; # We need a version of Test::More recent enough to support subtests @@ -102,6 +104,7 @@ BEGIN delete $ENV{LANGUAGE}; delete $ENV{LC_ALL}; $ENV{LC_MESSAGES} = 'C'; + setlocale(LC_ALL, ""); # This list should be kept in sync with pg_regress.c. my @envkeys = qw (

view thread (17+ messages)  latest in thread

Message-ID: <4076950.1681139381@sss.pgh.pa.us>
Permalink:  ../4076950.1681139381@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4076950.1681139381@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, aleksander@timescale.com, aekorotkov@gmail.com, andrew@dunslane.net
  Subject: Re: pgsql: psql: add an optional execution-count limit to \watch.
  In-Reply-To: <4076950.1681139381@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox