Cause: org.postgresql.util.PSQLException: 错误: 字段 “is_active_“ 的类型为 smallint, 但表达式的类型为 boolean

出现原因:项目使用的mysql数据库切换到postgres数据库,数据迁移过去,部分字段类型自动更改

具体操作:
1 查看当前数据库boolean类型的转换规则
可以看到,初始化数据库后,默认只有integer类型的显示转换。

select castsource::regtype,casttarget::regtype,castcontext,castfunc from pg_cast where castsource=‘boolean’::regtype;

2 修改integer类型的转换为隐式转换
update pg_cast set castcontext=‘i’ where castsource = ‘boolean’::regtype and casttarget=‘integer’::regtype;

3 添加boolean类型转换smallint类型的隐式转换
添加boolean类型转换smallint类型的自定义函数

create or replace function boolean2smallint(boolean) returns smallint as KaTeX parse error: Can't use function '$' in math mode at position 15: begin if $̲1 = true then … language plpgsql;

添加boolean类型转换smallint类型的隐式转换规则

create cast(boolean as smallint) with function boolean2smallint(boolean) as implicit;

4.修改完成后,再次查看当前数据库boolean类型的转换规则,可以看到,boolean类型有了转换integer和smallint类型的隐式转换规则。
在这里插入图片描述
文献来源:
原文链接:https://blog.csdn.net/weixin_43128854/article/details/130759812

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值