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

Exception in Postgres inserting None value for Option[JsonValue[...]] or Option[JsonbValue[...]] fields #3022

Closed
vladimirkl opened this issue Apr 23, 2024 · 0 comments · Fixed by #3023

Comments

@vladimirkl
Copy link
Contributor

vladimirkl commented Apr 23, 2024

Version: v4.8.3
Module: quill-jdbc-zio
Database: Postgres

Expected behavior

It should be possible to define case class with Option[JsonValue[...]] or Option[JsonbValue[...]] field, set value to None, and save to Postgres table with nullable json or json column using quill query with insertValue(...)

Actual behavior

Postgres throws exception when saving None values for Option[JsonValue[...]] or Option[JsonbValue[...]] fields:
ERROR: column "..." is of type json but expression is of type character varying

Steps to reproduce the behavior

 case class PersonJson(name: String, age: Int)
 case class JsonOptEntity(name: String, value: Option[JsonValue[PersonJson]])

 val jsonOptQuery  = quote(querySchema[JsonOptEntity]("JsonEntity"))
 val value = JsonOptEntity("JoeEntity", None)
 testContext.run(jsonOptQuery.insertValue(lift(value)))  // throws exception

Similar reproduction is for Option[JsonbValue[...]]

Workaround

override entityEncoder and astEncoder methods in custom Postgres context and set sqlType to Types.OTHER.

@getquill/maintainers

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