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

Add binary parsing for interval type #236

Open
morris25 opened this issue Oct 6, 2021 · 1 comment
Open

Add binary parsing for interval type #236

morris25 opened this issue Oct 6, 2021 · 1 comment

Comments

@morris25
Copy link
Contributor

morris25 commented Oct 6, 2021

We have a postgres table that contains intervals and are using binary parsing on all our other tables to increase query speed in our internal database support package. We are currently running into the nested error when trying to run queries on the new table due to the interval data failing to parse.

  nested task error: Couldn't parse ,? as interval using regex r"^P(?:(?<Year>-?\d+)Y)?(?:(?<Month>-?\d+)M)?(?:(?<Day>-?\d+)D)?(?:T(?:(?<Hour>-?\d+)H)?(?:(?<Minute>-?\d+)M)?(?:(?<Second>(?<whole_seconds>-?\d+)(?:\.(?<frac_seconds>\d{1,9}))?)S)?)?$"
    Stacktrace:
      [1] error(s::String)
        @ Base ./error.jl:33
      [2] pqparse(#unused#::Type{Dates.CompoundPeriod}, str::String)
        @ LibPQ ~/.julia/packages/LibPQ/IcOLJ/src/parsing.jl:444
      [3] parse(#unused#::Type{Dates.CompoundPeriod}, pqv::LibPQ.PQValue{0x000004a2, true})
        @ LibPQ ~/.julia/packages/LibPQ/IcOLJ/src/parsing.jl:127
      [4] (::LibPQ.var"#parse_type#79"{DataType})(pqv::LibPQ.PQValue{0x000004a2, true})
        @ LibPQ ~/.julia/packages/LibPQ/IcOLJ/src/parsing.jl:644
      [5] getindex(jl_result::LibPQ.Result{true}, row::Int64, col::Int64)
        @ LibPQ ~/.julia/packages/LibPQ/IcOLJ/src/results.jl:536
      [6] getproperty(pqrow::LibPQ.Row, name::Symbol)
        @ LibPQ ~/.julia/packages/LibPQ/IcOLJ/src/tables.jl:37
      [7] getcolumn
        @ ~/.julia/packages/Tables/OWzlh/src/Tables.jl:102 [inlined]
      [8] getcolumn
        @ ~/.julia/packages/Tables/OWzlh/src/Tables.jl:103 [inlined]
      [9] eachcolumn
        @ ~/.julia/packages/Tables/OWzlh/src/utils.jl:70 [inlined]
     [10] writerow(buf::Vector{UInt8}, pos::Base.RefValue{Int64}, len::Int64, io::IOStream, sch::Tables.Schema{(:release_date, :target_start, :target_end, :region, :tag, :target_bounds, :horizon, :temperature, :target), Tuple{Union{Missing, ZonedDateTime}, Union{Missing, ZonedDateTime}, Union{Missing, ZonedDateTime}, Union{Missing, String}, Union{Missing, String}, Union{Missing, Int16}, Union{Missing, Dates.CompoundPeriod}, Union{Missing, Float64}, Union{Missing, Interval{ZonedDateTime, L, R} where {L<:Bound, R<:Bound}}}}, row::LibPQ.Row, cols::Int64, opts::CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)})
        @ CSV ~/.julia/packages/CSV/owrEo/src/write.jl:367
@iamed2
Copy link
Owner

iamed2 commented Oct 6, 2021

https://github.com/postgres/postgres/blob/e94c1a55dada49772622d2be2d17a2a9973b2661/src/backend/utils/adt/timestamp.c#L980

The AdjustIntervalForTypmod function looks difficult to understand. Mostly I think it is truncating, but I'm not sure what the precision section does and I don't have time to look into it right now. Maybe it is easy or maybe it is not.

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