Search code examples
postgresqlscalaslicksqldatatypes

Handling Postgres json datatype in slick, scala


I have a Postgres 'json' column in my schema. This is my column mapping in my code:

def my_col = column[Option[String]]("my_col")

Which doesn't work, the stack trace I get when inserting says:

column "my_col" is of type json but expression is of type character varying

I tried this too:

def my_col = column[Option[String]]("my_col", O.SqlType("json"))

Which also yields the same error.


Solution

  • The problem is that there are no standard json data type in java/scala. So you need to write 'wrapper'. By the link below author did it handling json on db level:

    http://www.pateldenish.com/2013/05/inserting-json-data-into-postgres-using-jdbc-driver.html