-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add dialect param to use double precision for float64 in Postgres #11495
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
|
||
// Does the dialect use DOUBLE PRECISION to represent Float64 rather than DOUBLE? | ||
// E.g. Postgres uses DOUBLE PRECISION instead of DOUBLE | ||
fn use_double_precision_for_float64(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to #11494 (comment) what do you think about making this simply return the AST type directly?
fn use_double_precision_for_float64(&self) -> bool { | |
fn use_double_precision_for_float64(&self) -> sqlparser::ast::DataType { |
That is likely a more flexible API -- this formulation seems very narrow for postgres vs MySQL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alamb , thanks for the feedback! Directly return AST type seems clearer and more flexible to me. I update the changes in my newest commit, please take a look when you are available:
- Return
sqlparser::ast::DataType
instead ofbool
- Change the method name from
use_double_precision_for_float64
tofloat64_ast_dtype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution @Sevenannn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me -- thanks @Sevenannn
I think this PR has a conflict but once that is resolved I think it will be good to go.
Thank you for the contribution!
Hi @alamb, thanks for the review! the conflicts are resolved. |
Thanks again @Sevenannn |
…ache#11495) * Add dialect param to use double precision for float64 in Postgres * return ast data type instead of bool * Fix errors in merging * fix
…ache#11495) * Add dialect param to use double precision for float64 in Postgres * return ast data type instead of bool * Fix errors in merging * fix
Which issue does this PR close?
This PR addresses Float64 unparser issue producing an invalid CAST COL TO DOUBLE for Postgres.
Rationale for this change
The equivalence of arrow Expr::FLOAT64 type is DOUBLE PRECISION in Postgres, however it's currently converted into DOUBLE, which causes Postgres query failures
What changes are included in this PR?
See "What issue does this PR close"
Are these changes tested?
Yes, unit tests added and passed.
Are there any user-facing changes?
CustomDialectBuilde supports use_double_precision_for_float64 that can be used to specify whether DOUBLE vs DOUBLE PRECISION data type should be used for Float64 unparsing.