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

业务场景:

在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,就在对应的参数后面加上::类型这样的格式即可,如下:
在这里插入图片描述

至此,问题解决!


猜你喜欢

转载自blog.csdn.net/qq_25112523/article/details/109319183
今日推荐