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

How to prevent automatic casting #9853

Closed
BrandonKowalski opened this issue Feb 19, 2020 · 2 comments
Closed

How to prevent automatic casting #9853

BrandonKowalski opened this issue Feb 19, 2020 · 2 comments

Comments

@BrandonKowalski
Copy link

BrandonKowalski commented Feb 19, 2020

Your question: How can I prevent automatic casting?

Versions:

  • jOOQ: 3.13.0
  • Java: AdoptOpenJDK13
  • Database: PostgreSQL 12.1
  • OS: Java Application macOS 10.15.3 / PostgreSQL 12.1 Official Docker Container
  • JDBC Driver: org.postgresql.postgresql:42.2.10

This question is very similar to #1659.

I have a field with the type int4range[]. On insert, I receive the following exception:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "any"

I set my logger to debug to examine the generated SQL. Like #1659, JOOQ is attempting to cast this "field_name" = ?::any[]

#1659 referenced Factory.field(String) as a means to stop this casting. This has been deprecated. What is the correct way in which to stop this casting?

@lukaseder
Copy link
Member

Thank you very much for your message.

Currently, you cannot stop our automatic casting for arbitrary data types. In PostgreSQL, explicit casts are required in a variety of cases, so by default, jOOQ often generates these.

You can, however, implement a data type binding for your int4range[] type, and usea that in your generated code:
https://www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-bindings

I hope this helps

@BrandonKowalski
Copy link
Author

Thanks! I’ll give that a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants