Postgresql JSONB insert allowed

1,992 views
Skip to first unread message

Gary Malouf

unread,
Sep 28, 2015, 5:15:14 PM9/28/15
to ScalikeJDBC Users Group
When I try to insert otherwise valid json into a postgres table with a jsonb field, I get the following error:

org.postgresql.util.PSQLException: ERROR: column "data" is of type jsonb but expression is of type character varying

  Hint: You will need to rewrite or cast the expression.


Is there a way to explicitly cast the expression within scalalikejdbc?


Gary Malouf

unread,
Sep 28, 2015, 5:36:04 PM9/28/15
to ScalikeJDBC Users Group
The solution is to replace the '?' in your insert statement with 

to_json(?::json)::jsonb

which is transforming a string to json then casting that to jsonb.
Reply all
Reply to author
Forward
0 new messages