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

Documentation: Dec64 type conversion to Integer #288

Closed
aalexandersson opened this issue Jun 2, 2020 · 1 comment
Closed

Documentation: Dec64 type conversion to Integer #288

aalexandersson opened this issue Jun 2, 2020 · 1 comment

Comments

@aalexandersson
Copy link

aalexandersson commented Jun 2, 2020

I am a Julia beginner and do not know how to convert column type Union{Missing, Dec64} to Integer in the output from ODBC. I am using Julia 1.4.2 and ODBC 1.0.0 on Windows 10 with an Oracle database driver.

The result of DBInterface.execute(conn, sql) on my SQL query is ODBC.Cursor{false,false} which at the end includes "metadata" with a 3x7 Array{Any,2} with two columns for ZIPCODE_ZIP and ZIPCODE_COUNTY of column type Union{Missing, Dec64}.

Ideally, I would like to avoid the conversion and if possible simply extract the two Dec64 type columns as Integer.

I tried convert(Int32, get(x.ZIPCODE_ZIP)) (based on https://discourse.julialang.org/t/decfp-type-conversion-to-integer/5752 and https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/) but get error

MethodError: Cannot `convert` an object of type Array{Union{Missing, DecFP.Dec64},1} to an object of type Int32
Closest candidates are:
  convert(::Type{Int32}, !Matched::DecFP.Dec32) at C:\Users\aalexandersson\.julia\packages\DecFP\quvcm\src\DecFP.jl:454
  convert(::Type{Int32}, !Matched::DecFP.Dec64) at C:\Users\aalexandersson\.julia\packages\DecFP\quvcm\src\DecFP.jl:454
  convert(::Type{Int32}, !Matched::DecFP.Dec128) at C:\Users\aalexandersson\.julia\packages\DecFP\quvcm\src\DecFP.jl:454

Having a documented example of how to convert the data type or to get the wanted data type directly would be very helpful to me as a beginner for using ODBC.

Edit: I think display formatting is what I want, rather than conversion. This is the easiest solution I found to get rid of the decimals:

using PrettyTables
pretty_table(x, formatters = ft_printf("%.0f"))
@aalexandersson aalexandersson changed the title Dec64 type conversion to Integer Documentation: Dec64 type conversion to Integer Jun 3, 2020
@quinnj quinnj closed this as completed in f9e38fd Jun 3, 2020
@quinnj
Copy link
Member

quinnj commented Jun 3, 2020

Thanks for opening an issue! I added some example docs in the "Getting Started" section of the docs; hopefully that helps.

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