-
Notifications
You must be signed in to change notification settings - Fork 583
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
MySQL datatype discrepancy between DDL and CAST
#1589
Comments
mvzink
added a commit
to mvzink/datafusion-sqlparser-rs
that referenced
this issue
Feb 21, 2025
MySQL doesn't have the same set of possible CAST types as for e.g. column definitions. For example, it raises a syntax error for `CAST(1 AS INTEGER SIGNED)` and instead expects `CAST(1 AS SIGNED INTEGER)`. This patch takes a somewhat unfortunate route of 1) adding a boolean flag that modifies the `parse_data_type` match expression, and 2) storing whether it was parsed this way in the `Expr::Cast` AST node to be used during formatting. Feedback and ideas for alternative approaches are very welcome. Closes apache#1589
mvzink
added a commit
to mvzink/datafusion-sqlparser-rs
that referenced
this issue
Feb 21, 2025
MySQL doesn't have the same set of possible CAST types as for e.g. column definitions. For example, it raises a syntax error for `CAST(1 AS INTEGER SIGNED)` and instead expects `CAST(1 AS SIGNED INTEGER)`. This patch takes a somewhat unfortunate route of 1) adding a boolean flag that modifies the `parse_data_type` match expression, and 2) storing whether it was parsed this way in the `Expr::Cast` AST node to be used during formatting. Feedback and ideas for alternative approaches are very welcome. Closes apache#1589
mvzink
added a commit
to mvzink/datafusion-sqlparser-rs
that referenced
this issue
Feb 24, 2025
MySQL doesn't have the same set of possible CAST types as for e.g. column definitions. For example, it raises a syntax error for `CAST(1 AS INTEGER SIGNED)` and instead expects `CAST(1 AS SIGNED INTEGER)`. We retain the current somewhat permissive datatype parsing behavior (e.g. allowing `CAST(1 AS BIGINT)` even though MySQL would raise a syntax error), and add two datatypes for this specific case (`SIGNED [INTEGER]` and `UNSIGNED [INTEGER]`). Closes apache#1589
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In MySQL, creating a column expects
integer unsigned
(as an "attribute" on the integer type, see docs), whileCAST
expectsunsigned integer
or even justunsigned
(see docs).This can be seen in this transcript:
sqlparser just has one
parse_data_type
procedure used in both contexts, which currently parses according to the column datatype rules, which means it fails to parseCAST
correctly.Incorrectly failing to parse
unsigned integer
:Incorrectly succeeding in parsing
integer unsigned
:I don't know if it would be better to have a second, somewhat redundant
parse_data_type_for_cast
which we enter for mysql-alikes, or add some special casing in the existingparse_data_type
. That may depend on whether there are other discrepancies between create and cast that need to be addressed. Not sure when I'll have time to address this, but any feedback on approach would be welcome.The text was updated successfully, but these errors were encountered: