Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numbers displayed as 1.450817032e+ #448

Open
hossam-houssien opened this issue Mar 10, 2024 · 5 comments
Open

numbers displayed as 1.450817032e+ #448

hossam-houssien opened this issue Mar 10, 2024 · 5 comments

Comments

@hossam-houssien
Copy link

numbers displayed as "1.450817032e+" it should be displayed as 1450817.032,
tried to use -P numericlocale=on, this displayed as 1,450,817.032, but we required to be displayed as 1450817.032

env

  • OS: Windows
  • usql 0.17.5
@kenshaw
Copy link
Member

kenshaw commented Mar 10, 2024

Thanks for reporting this. Not sure what the issue is, I'll look into it.

@kenshaw
Copy link
Member

kenshaw commented Mar 10, 2024

This appears to be working; can you share more information about the table/query you were using? My guess is that this was returned back not as the type you expected.

@kenshaw
Copy link
Member

kenshaw commented Mar 10, 2024

With / without the -P setting on the command-line:

$ usql -P numericlocale=on pg:// -c "select '1450817.032'::real"
Connected with driver postgres (PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1))
   float4    
-------------
 1,450,817.0 
(1 row)

$ usql pg:// -c "select '1450817.032'::real"
Connected with driver postgres (PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1))
    float4    
--------------
 1.450817e+06 
(1 row)

@hossam-houssien
Copy link
Author

It is working like you showing, and like I like show earlier, but what I am asking for it should be displayed as 1450817.0 without the thousands separator

@kenshaw
Copy link
Member

kenshaw commented Mar 31, 2024

Compare the output for the following script:

select '1251258098.1555901285'::numeric;
select '1251258098.1555901285'::float4;
select '1251258098.1555901285'::float8;
select '1251258098.1555901285'::double precision;

With psql:

$ psql -f f.sql postgres://postgres:P4ssw0rd@localhost
        numeric        
-----------------------
 1251258098.1555901285
(1 row)

    float4     
---------------
 1.2512581e+09
(1 row)

      float8      
------------------
 1251258098.15559
(1 row)

      float8      
------------------
 1251258098.15559
(1 row)

With usql:

$ usql -f f.sql postgres://postgres:P4ssw0rd@localhost
        numeric        
-----------------------
 1251258098.1555901285 
(1 row)

    float4     
---------------
 1.2512581e+09 
(1 row)

        float8        
----------------------
 1.25125809815559e+09 
(1 row)

        float8        
----------------------
 1.25125809815559e+09 
(1 row)

The differences here are in the difference between how Go and C treat their numeric formatting. I agree Go seems to be wrong here for extremely large numbers, and I'll look into seeing if we can get something closer to psql's formatting in the future.

In the interim, I would suggest casting your number as a string, or to the numeric type, or otherwise use the database's formatting functionality. This is an extremely low priority to change/fix, mostly due to the non-trivial complexity involved.

(caveat: apologies in advance if I'm mistaken about psql just using printf or a variant of it, as I'm mostly assuming here without looking at psql's source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants