ArgumentError: invalid BigInt: "0E-24" in LibPQ / Decimals

I’m running a simple SQL select from a table and getting the stacktrace below. I have been using this code for months and today is the first time I’ve seen it so it could be related to me running Pkg.update() recently.

First of all, should “0E-24” be a valid Decimal in the Decimals package? If so, I guess there is a bug in that. If not, is there some way to override how libpq is parsing what it gets back to workaround this problem? Using a separate SQL tool, it appears there is a 0 in the column that is causing the problem, so I’m not sure why it’s showing 0E-24.

julia> rowtable(execute(db, "select * from mytable where id=111"))
ERROR: ArgumentError: invalid BigInt: "0E-24"
Stacktrace:
  [1] tryparse_internal(#unused#::Type{BigInt}, s::String, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
    @ Base.GMP .\gmp.jl:285
  [2] parse(::Type{BigInt}, s::String; base::Nothing)
    @ Base .\parse.jl:241
  [3] parse
    @ .\parse.jl:241 [inlined]
  [4] parameters
    @ C:\Users\joel\.julia\packages\Decimals\Sb4j1\src\decimal.jl:19 [inlined]
  [5] parse(#unused#::Type{Decimals.Decimal}, str::String)
    @ Decimals C:\Users\joel\.julia\packages\Decimals\Sb4j1\src\decimal.jl:6
  [6] pqparse
    @ C:\Users\joel\.julia\packages\LibPQ\6itxv\src\parsing.jl:138 [inlined]
  [7] parse(#unused#::Type{Decimals.Decimal}, pqv::LibPQ.PQValue{0x000006a4, false})
    @ LibPQ C:\Users\joel\.julia\packages\LibPQ\6itxv\src\parsing.jl:127
  [8] (::LibPQ.var"#parse_type#82"{DataType})(pqv::LibPQ.PQValue{0x000006a4, false})
    @ LibPQ C:\Users\joel\.julia\packages\LibPQ\6itxv\src\parsing.jl:690
  [9] getindex(jl_result::LibPQ.Result{false}, row::Int64, col::Int64)
    @ LibPQ C:\Users\joel\.julia\packages\LibPQ\6itxv\src\results.jl:545
 [10] getproperty(pqrow::LibPQ.Row, name::Symbol)
    @ LibPQ C:\Users\joel\.julia\packages\LibPQ\6itxv\src\tables.jl:37
 [11] getcolumn
    @ C:\Users\joel\.julia\packages\Tables\PxO1m\src\Tables.jl:102 [inlined]
 [12] getcolumn
    @ C:\Users\joel\.julia\packages\Tables\PxO1m\src\Tables.jl:103 [inlined]
 [13] macro expansion
    @ C:\Users\joel\.julia\packages\Tables\PxO1m\src\namedtuples.jl:50 [inlined]
 [14] _iterate(rows::Tables.NamedTupleIterator{Tables.Schema{(:tid, :tscreated, :primitdir, :targetdate, :underbid, :underask, :prilldiropen, :prilldirclose, :tsfilled, :tsclosed, :status), Tuple{Union{Missing, Int64}, Union{Missing, DateTime}, Union{Missing, Decimals.Decimal}, Union{Missing, Date}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, DateTime}, Union{Missing, DateTime}, Union{Missing, String}}}, LibPQ.Result{false}}, st::Tuple{})
    @ Tables C:\Users\joel\.julia\packages\Tables\PxO1m\src\namedtuples.jl:41
 [15] iterate
    @ C:\Users\joel\.julia\packages\Tables\PxO1m\src\namedtuples.jl:62 [inlined]
 [16] iterate
    @ C:\Users\joel\.julia\packages\Tables\PxO1m\src\namedtuples.jl:61 [inlined]
 [17] copyto!(dest::Vector{NamedTuple{(:tid, :tscreated, :primitdir, :targetdate, :underbid, :underask, :prilldiropen, :prilldirclose, :tsfilled, :tsclosed, :status), Tuple{Union{Missing, Int64}, Union{Missing, DateTime}, 
Union{Missing, Decimals.Decimal}, Union{Missing, Date}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, DateTime}, Union{Missing, DateTime}, Union{Missing, String}}}}, src::Tables.NamedTupleIterator{Tables.Schema{(:tid, :tscreated, :primitdir, :targetdate, :underbid, :underask, :prilldiropen, :prilldirclose, :tsfilled, :tsclosed, :status), Tuple{Union{Missing, Int64}, Union{Missing, DateTime}, Union{Missing, Decimals.Decimal}, Union{Missing, Date}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, DateTime}, Union{Missing, DateTime}, Union{Missing, String}}}, LibPQ.Result{false}})
    @ Base .\abstractarray.jl:890
 [18] _collect
    @ .\array.jl:655 [inlined]
 [19] collect(itr::Tables.NamedTupleIterator{Tables.Schema{(:tid, :tscreated, :primitdir, :targetdate, :underbid, :underask, :prilldiropen, :prilldirclose, :tsfilled, :tsclosed, :status), Tuple{Union{Missing, Int64}, Union{Missing, DateTime}, Union{Missing, Decimals.Decimal}, Union{Missing, Date}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, Decimals.Decimal}, Union{Missing, DateTime}, Union{Missing, DateTime}, Union{Missing, String}}}, LibPQ.Result{false}})
    @ Base .\array.jl:649
 [20] rowtable(itr::LibPQ.Result{false})
    @ Tables C:\Users\joel\.julia\packages\Tables\PxO1m\src\namedtuples.jl:106
 [21] top-level scope
    @ REPL[18]:1

strange …

Please create a minimal debug example:

  • Create a minimal table - with 1column + 1 record
    • and run “pg_dump”
  • Add a minimal Julia code

Please add some metadata:

  • Julia version?
  • LibPQ version?
  • Postgresql version?

Julia is version 1.7.2
LibPQ is latest (just ran update)
Postgresq;… it’s actually a postgres compatible cloud database, so if real postgresql would never return “0E-24”, then that could be the issue, otherwise, probably doesn’t matter.

I have a table with column types numeric(10,3) and I’m selecting from a view that sums across it. One row has a value of .01, and another with -.01, thus the 0. I realize this might be why it suddenly happened, because it might be the first time I have a net 0 in that view’s column.

I figured out a workaround. Defining this function fixes it:

function LibPQ.pqparse(::Type{Decimal}, str::AbstractString)
	parse(Decimal, lowercase(str))
end

There might be a better way to implement that, but it demonstrates the solution. The problem is the capital E. Decimal will only accept lower case e’s.

1 Like