2

I want to insert json string, which has no predefined structure i.e. key value formats are not fixed, into a postgres column with jsonb datatype. My application uses HikariCP alongwith JPA.

Earlier I had the following generic cast operation in postgres to achieve the above but its not recommended by my DBA as it fundamentally alters the varchar datatype.

CREATE CAST (character varying AS jsonb) WITH INOUT AS IMPLICIT;

While looking for application side alternatives, I came across setting stringtype as unspecified like below

spring:   
  profiles: development   
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://127.0.0.1/mydb
    username: my_user
    password: 'my_password'
    hikari:
      auto-commit: true
      maximumPoolSize: 2
      leakDetectionThreshold: 60000
    tomcat:
      connection-properties: stringtype=unspecified

The above configuration doesn't help. connection-properties doesn't seem to be a direct property of datasource. Various answers on forums just tell you to set stringtype=unspecified in connection-properties but a clear working answer would be of more help.

1 Answer 1

1

While thinking about it, I realized that this property must be set HikariCP. When I looked through various parameters it allows me to set, I came across data-source-properties. Following is what I discovered as the solution to above problem

hikari:
  data-source-properties: stringtype=unspecified
Sign up to request clarification or add additional context in comments.

2 Comments

For those who are looking for the flattened version spring.datasource.hikari.data-source-properties.stringtype=unspecified
this is good for json, but for me breaks LIKE query with emty parameters as side effect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.