您当前的位置: 首页 >  慌途L ar

PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying

慌途L 发布时间:2020-10-27 20:01:41 ,浏览量:3

业务场景:

在MyBatis中对Postgresql数据库的表数据进行update操作,报以下错误:

  • 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. 在这里插入图片描述

  • Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = character varying 建议:No operator matches the given name and argument types. You might need to add explicit type casts. 在这里插入图片描述

原因:

由于Postgresql数据库的数据类型跟MySQL不一致,导致惯性思维在MyBatis数据库中写sql语句,导致报错。原因其实是同一个,就是接受的参数的数据类型和Postgresql数据库的不一致。

我这里的uuiddata分别是uuid类型和jsonb类型,如下图: 在这里插入图片描述

然后MyBatis中的sql如下: 在这里插入图片描述 场景就是这样。

解决方法:

在每个类型后面加上对应的类型转换,如uuid类型和jsonb,就在对应的参数后面加上::类型这样的格式即可,如下: 在这里插入图片描述

至此,问题解决!

关注
打赏
1688896170
查看更多评论

慌途L

暂无认证

  • 3浏览

    0关注

    118博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.4333s