Comments (3)
Only columns with type numeric
/decimal
will appear this way; float4
/real
and float8
/double precision
will not.
The numeric
type is an arbitrary-precision number that cannot be represented fully in a Float64
. However, Decimals.Decimal
is not a great type, and a replacement (or improvements to that package) would be welcome.
You can either force the type in Julia:
julia> execute(conn, sql; type_map=Dict(:numeric => Float64)).column_types
3-element Vector{Type}:
Float64
Float64
Float64
or in SQL:
julia> sql="""
select avg(1.0)::float8 as average, 1.0::float8 as float_number, 0.0000000001::float8 as really_small_number;
"""
"select avg(1.0)::float8 as average, 1.0::float8 as float_number, 0.0000000001::float8 as really_small_number;\n"
julia> execute(conn, sql).column_types
3-element Vector{Type}:
Float64
Float64
Float64
from libpq.jl.
Thank you for the explanation, @iamed2!
I've been eyeing type_map
in the docs to force the conversion, so the example is much appreciated.
I'll close the issue as LibPQ works as expected.
Some additional background:
I've used a standard pattern of download SQL -> DataFrame -> save to .arrow for persistence/version control.
Upon opening, my saved data was rubbish.
It turns out that Arrow.write(...;compress=:lz4) didn't know what to do with Decimals type and saved it however without any warning (an issue opened here).
As for the python side, you're right.
I've just checked that both psycopg2 and sqlalchemy (using the former as the driver) return decimals.
The challenge is that I (and perhaps others) use Pandas to download data (pd.read_sql_query), which forces the Float type, so I will have never seen the decimal type come out of a SQL / I didn't know it's the expected behaviour.
Good learning!
from libpq.jl.
psycopg2
in Python does the same thing, using the decimal
module in Python's standard library.
https://www.psycopg.org/docs/faq.html#faq-float
from libpq.jl.
Related Issues (20)
- UndefVarError: LIBPQ_HANDLE not defined HOT 1
- Support for LISTEN/NOTIFY HOT 5
- Problems with connection timeouts and multihreadding HOT 5
- collect on LibPQ.Column allocates a lot HOT 1
- Memory Leak? HOT 4
- LibPQ and local peer trust ("ident") HOT 4
- Trying to implement large object support HOT 4
- Large select queries running 5-10x slower than with psql HOT 7
- Support UUIDs with binary_format=true HOT 1
- Make Tables.rowtable(result) as fast as Tables.rowtable(Tables.columntable(result))
- `tryparse` Inexact Error HOT 5
- Docs links return 404 HOT 3
- Using array_agg results in a string HOT 2
- I install LibPQ but test fails. HOT 1
- Guess when there is no server running in tests and suggest users install one
- Multiple `async_execute`s may not always execute in sequence?
- `execute` and `async_execute` exception handling difference
- `LibPQ`.`async_execute`'s overhead is around 3ms HOT 2
- Add functions for closing prepared statements (requires PostgreSQL 17 release and corresponding libpq_jll)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libpq.jl.