Windows locales and tests portability

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Windows locales and tests portability
Date: 2026-02-06 07:02:35
Message-ID: 9247F741-DDAB-4005-93D2-9C6D4F3495C3@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers!

I'm toying with Windows machine. It's nice, fast, run cool games, so I decided to keep it and make a BF animal on top. The problem is I have RU locale.

PostgreSQL::Test::Utils.pm (lines 113-115) explicitly sets:
$ENV{LC_NUMERIC} = 'C';
setlocale(LC_ALL, "");
This makes Perl format numbers with . as the decimal separator.

Windows MSVC strtod(): seems to ignore environment variables entirely and use the system's regional settings (Russian locale ,)
On Unix, environment variables like LC_NUMERIC control both Perl and C library functions like strtod(). Looks like on Windows with MSVC, the C runtime gets its locale from the Windows regional settings, not from environment variables.

FWIW I used strawberry perl 5, version 42, subversion 0 (v5.42.0) built for MSWin32-x64-multi-thread. Windows 11 Pro 23H2 build 22631.4890.

I propose attached ugly fix, it makes my box happy and works on CI machines.

In pg_test_timing fix is easy. It just accept [,.] as a decimal separator. AFAIK that would solve the problem for Russian, Brazilian, Indonesia, German, Italian, Polish etc locales. There are some other separators, but with really small fraction, I could add them into regex, but with a wiki-page-like comment... so here's [,.]

For \watch tests we need to format number that would be acceptable to strtod(), so I resorted to printing this number by psql. Luckily in standard SQL syntax so far, the period (.) is the universal decimal separator for numeric literals in a query.

Perhaps, I should just switch my machine to locale with dot too. But just in case if we really want tests on Windows with locales, PFA.
I did not consider seriously bashing with Utils.pm setlocale(). But maybe I should try.

WDYT?

Best regards, Andrey Borodin.

Attachment Content-Type Size
0001-Fix-TAP-tests-for-Windows-with-non-C-numeric-locales.patch application/octet-stream 5.8 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Ryo Matsumura (Fujitsu) 2026-02-06 07:11:07 Concerns regarding code in pgstat_backend.c
Previous Message Japin Li 2026-02-06 06:44:35 Re: Make wal_receiver_timeout configurable per subscription