将jsonb插入postgresql

时间:2017-10-10 12:15:46

标签: activejdbc

我想创建一个对象并将其保存到数据库

Log l = new Log();

l.setTimestamp("creation_date", Util.getCurrentTimestamp());
l.setString("app_name", "name");
l.setString("log_type", "type");
l.setLong("user_id", 9l);
l.setLong("module_element_id", 9);
l.set("info", JsonHelper.toJsonString("{}"));
l.save();

我尝试过多次尝试,但总是得到这个错误:

ERROR: column "info" is of type jsonb but expression is of type character varying

如何插入jsonb?

编辑(DDL):

- 表:public.log

- DROP TABLE public.log;

CREATE TABLE public.log
(
  id bigint NOT NULL DEFAULT nextval('log_id_seq'::regclass),
  creation_date timestamp without time zone,
  app_name text,
  log_type text,
  user_id bigint,
  module_element_type bigint,
  info jsonb,
  CONSTRAINT log_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public.log
  OWNER TO postgres;

1 个答案:

答案 0 :(得分:0)

目前框架中缺少此实现。它已在https://github.com/javalite/activejdbc/issues/640中报告过。如果您可以帮助跟踪Postgres文档中所有与PreparedStatement一起使用此语法的Postgres数据类型:

UPDATE my_table SET status = ?::status_type WHERE id = ?

然后,我将能够快速为PostgreSQL方言实现它:https://github.com/javalite/activejdbc/blob/master/activejdbc/src/main/java/org/javalite/activejdbc/dialects/PostgreSQLDialect.java