0
votes

I am trying to insert json in postgress column which is json

But in slick generation it has generated like below:

val taskVariables: Rep[Option[String]] = column[Option[String]]("TaskVariables", O.Length(2147483647,varying=false), O.Default(None))

to insert it I am coding like this:

    val insertRecord = Record(id = 0L,taskVariables = Some(Map("a">"b").asJson)
    for{
      result<-insertEntity(insertRecord)
    }yield result
  }

which is throwing error while inserting like below:

"message": "column "TaskVariables" is of type json but expression is of type character varying", "ex": "org.postgresql.util.PSQLException: ERROR: column "TaskVariables" is of type json but expression is of type character varying Hint: You will need to rewrite or cast the expression. Position: 392 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:132) at

1

1 Answers

0
votes

I'm not so sure what are you really trying to do, but this are the following primitive types are supported out of the box for JDBC-based databases in JdbcProfile (with certain limitations imposed by the individual database drivers):

Nullable columns are represented by Option[T] where T is one of the supported primitive types.

Numeric types: Byte, Short, Int, Long, BigDecimal, Float, Double
LOB types: java.sql.Blob, java.sql.Clob, Array[Byte]
Date types: java.sql.Date, java.sql.Time, java.sql.Timestamp
Boolean
String
Unit
java.util.UUID
  • If your database layout requires schema names, you can specify the schema name for a table .

like this one:

class Coffees(tag: Tag)
  extends Table[(String, Int, Double, Int, Int)](tag, Some("MYSCHEMA"), "COFFEES") {
  //...
}

You can read more here.