[PATCH] Honor LC_NUMERIC environment variable on Windows

Started by Andrew Billeabout 1 month ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253879
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 23, 2026 at 03:46 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253879_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253879_1 && git checkout t253879_1

Patchset v1 (message #1) is on t253879_1

Jump to latest
#1Andrew Bille
andrewbille@gmail.com

Hi,

While running the TAP tests on Windows with the system locale set to
Russian, I found that frontend programs don't honor LC_NUMERIC from the
environment.

PostgreSQL::Test::Utils explicitly sets:

$ENV{LC_NUMERIC} = 'C';

but pg_test_timing still produces output such as:

Average loop time including overhead: 21,30 ns
Observed timing durations up to 99,9900%:

instead of using a dot as the decimal separator.

This is not specific to pg_test_timing. For example, psql also fails to
parse decimal arguments such as:

\watch 0.01

when the Windows user locale uses a comma as the decimal separator.

I reduced this to the behavior of the Windows CRT. With the environment:

LANG=C
LC_ALL=C
LC_NUMERIC=C

a small MSVC test program shows that:

setlocale(LC_ALL, "");

selects the Windows user locale (Russian_Russia.1251), with "," as the
decimal separator. Calling:

setlocale(LC_NUMERIC, "C");

explicitly afterwards restores the expected "." separator.

For comparison, on Linux I checked the locale selection behavior:

LANG=C -> "."
LANG=C, LC_NUMERIC=ru_RU.UTF-8 -> ","
LC_ALL=C, LC_NUMERIC=ru_RU.UTF-8 -> "."
LANG=C, LC_NUMERIC="" -> "."

The attached patch keeps the existing Windows behavior when LC_NUMERIC
is unset or empty, but explicitly applies a non-empty LC_NUMERIC
environment setting after setlocale(LC_ALL, "").

With the patch, pg_test_timing uses "." when LC_NUMERIC=C, and psql
correctly accepts decimal \watch intervals under a Russian Windows
system locale.

Tested on PostgreSQL master (20devel), Windows 11, MSVC 19.44.

Regards,
Andrew

Attachments:

t253879_1
0001-Honor-LC_NUMERIC-environment-variable-on-Windows.patchtext/x-patch; charset=US-ASCII; name=0001-Honor-LC_NUMERIC-environment-variable-on-Windows.patchDownload+15-1