how to insert json or jsonb on postgresql

888 views
Skip to first unread message

王华涛

unread,
Oct 20, 2015, 10:05:38 AM10/20/15
to Squeryl

this is my code:

 

class RoleData( var roleId: String, var data: String)

 

object Library extends Schema {

val roleData = table[RoleData]

on(roleData)(s => declare(

s.roleId is(primaryKey, indexed),

s.data is (dbType("jsonb"))

))

when i call :

roleData.insert(new RoleData("id3",jsonb))

the error happend :Caused by: org.postgresql.util.PSQLException: ERROR: column "data" is of type jsonb but expression is of type character varying

:You will need to rewrite or cast the expression.

  so ,my question is how to insert a jsonb string

王华涛

unread,
Oct 25, 2015, 10:16:09 PM10/25/15
to Squeryl
in 0.9.6-RC4,use s.data is (dbType("jsonb").explicitCast),it solved

在 2015年10月20日星期二 UTC+8下午10:05:38,王华涛写道:
Reply all
Reply to author
Forward
0 new messages