【问题标题】:value is of jsonb but expression is of type bigint error in postgresql值是 jsonb 但表达式是 postgresql 中的 bigint 类型错误
【发布时间】:2022-08-22 06:14:01
【问题描述】:

我正在尝试从 oracle 迁移到 postgresql。 在 oracle 中,我们将 @Lob 数据添加到用于保存大量数据的字段中。

@Lob
private String A_Value;

对于 postgresql,我们需要使用 json/jsonb 代替 lob 数据。我为此做了以下更改。

@TypeDefs({
   @TypeDef(name=\"json\", typeClass=JsonStringType.class),
   @TypeDef(name=\"jsonb\", typeClass=JsonBinaryType.class)
 
})
public class AbcM implements Serializable{
---------
@Type(type=\"jsonb\")
@Column(name=\"A_Value\", columnDefinition=\"jsonb\")
private String A_Value;
}

@Repository
public interface ARepository extends JPARepository<AuditM,Long>{}

##Impl class to save data
@Override
@Async
public CompletableFuture<String> saveRequest(AbcM model){
    ARepository.saveAndFlush(model);
}

##ERROR:列 A_Value 的类型为 jsonb,但表达式的类型为 bigint 重写或转换表达式

您能否建议我应该如何保存数据而不会出现任何错误。

    标签: spring spring-boot hibernate


    【解决方案1】:

    使用 postgres 函数 to_jsonb() 将 bigint 作为 jsonb 返回。

    例如:

    INSERT INTO my_table(jsonb_col)
    VALUES(to_jsonb(12345))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 2018-10-09
      • 2015-04-22
      • 2011-12-18
      • 2012-02-25
      相关资源
      最近更新 更多