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

H2 cast ('1' as unsigned integer) will throw Unknown data type: "UNSIGNED" #4046

Open
tszxxx opened this issue Apr 17, 2024 · 6 comments
Open

Comments

@tszxxx
Copy link

tszxxx commented Apr 17, 2024

H2:
config: spring.datasource.url: jdbc:h2:mem:testdb;MODE=MYSQL
sql: select cast ('1' as unsigned integer)
exception JdbcSQLNonTransientException Unknown data type: "UNSIGNED"

Maven + POM:
package: com.h2database - h2
version: 2.2.220

@tszxxx tszxxx changed the title H2 cast ('1' as unsigned integer) will throw Unknown data type: "UNSIGNED" H2 cast ('1' as unsigned integer) will throw Unknown data type: "UNSIGNED" Apr 17, 2024
@katzyn
Copy link
Contributor

katzyn commented Apr 18, 2024

Cast function in MySQL looks like standard cast specification, but it isn't the same, it uses some own names of data types, these names are different from actual names of data types in MySQL. unsigned integer here actually means bigint unsigned data type. On the same time, MySQL doesn't allow its own bigint unsigned data type to be used as a type name in cast. Some other data types can't be specified at all, even with different names. There is an almost 16-years-old bug: https://bugs.mysql.com/bug.php?id=34562

We can try to parse these { UNSIGNED | SIGNED } [ INTEGER | INT ] as BIGINT in MySQL and MariaDB compatibility modes of H2, it shouldn't be too problematic. But it will be much better to resolve this bug on MySQL side.

@Sintivrousai
Copy link

I would like to be assigned for the issue.

@tszxxx
Copy link
Author

tszxxx commented Apr 18, 2024

Cast function in MySQL looks like standard cast specification, but it isn't the same, it uses some own names of data types, these names are different from actual names of data types in MySQL. unsigned integer here actually means bigint unsigned data type. On the same time, MySQL doesn't allow its own bigint unsigned data type to be used as a type name in cast. Some other data types can't be specified at all, even with different names. There is an almost 16-years-old bug: https://bugs.mysql.com/bug.php?id=34562

We can try to parse these { UNSIGNED | SIGNED } [ INTEGER | INT ] as BIGINT in MySQL and MariaDB compatibility modes of H2, it shouldn't be too problematic. But it will be much better to resolve this bug on MySQL side.

Got that, I totally agree with you. But I may still need h2 to support this (even just ignore the unsigned identifier), otherwise I cannot make my SQL query compatible with MySql (v5.7).

@tszxxx
Copy link
Author

tszxxx commented Apr 18, 2024

I would like to be assigned for the issue.

I'm not sure about the standard process, should I assign anyone as the assignee, or the owner of the repo will do that?

@katzyn
Copy link
Contributor

katzyn commented Apr 19, 2024

You can send a pull request with your changes.

  1. This syntax should only be allowed within a cast specification and only if Mode.allNumericTypesHavePrecision is enabled (this flag controls MySQL-style deviations in data types).
  2. Standard cast specification should work as it worked before even if this flag is set.

@katzyn
Copy link
Contributor

katzyn commented Apr 19, 2024

Don't forget to add some tests.

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

3 participants