usql
usql copied to clipboard
bug: `numericlocale` does not seem to be respected
In psql
, the numericlocale
option uses the system locale to format numbers:
ubuntu=# \pset numericlocale on
ubuntu=# select 1234;
?column?
----------
1,234
(1 row)
In usql
this appears not to be respected:
pg:[email protected]/ubuntu=> \pset numericlocale on
Locale-adjusted numeric output is on.
pg:[email protected]/ubuntu=> select 1234;
?column?
----------
1234
(1 row)
While we try to copy psql
's functionality as much as possible, this is not going to be changed anytime soon. The issue here is that it's part of C's underlying formatting functionality, and this can't be changed easily with in the usql
source code. I'd suggest using the database's own formatting functionality if you really need to present numbers in a format different from what usql
does by default.
Interesting, thanks for the context. Updating the output might be helpful for confusion reduction.
@kenshaw Should we remove it from https://github.com/xo/usql/blob/d5382e9c4de30b3f82d545e17d6636bd0af61eae/env/types.go#L83 then?
Just pushed a change for this, which will go out in the next tagged release. You can now \pset numericlocale
which will use the new \pset locale
setting to format numbers. This value by default is read from your operating system.
The locale
variable needs to be a BCP-47 format, and understood by golang.org/x/text/language.Parse:
$ usql pg://booktest:booktest@localhost
Connected with driver postgres (PostgreSQL 14.5 (Debian 14.5-1.pgdg110+1))
Type "help" for help.
pg:booktest@localhost=> select * from test;
a | b
-----------+-------
15 | 15
179544.15 | 90218
(2 rows)
pg:booktest@localhost=> \pset numericlocale
Locale-adjusted numeric output is on.
pg:booktest@localhost=> select * from test;
a | b
------------+--------
15.0 | 15
179,544.15 | 90,218
(2 rows)
pg:booktest@localhost=> \pset locale ta-IN
Locale is "ta-IN".
pg:booktest@localhost=> select * from test;
a | b
-------------+--------
15.0 | 15
1,79,544.15 | 90,218
(2 rows)
pg:booktest@localhost=>
Amazing news! Confirmed it looks good with the latest commit!