Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = character varying 建议:No operator matches the given name and argument types. You might need to add explicit type casts.
如何解决?
在 PostgreSQL 中,当你遇到错误消息 ERROR: operator does not exist: bigint = character varying
时,这通常意味着你在进行比较操作时,左右两个操作数的数据类型不匹配。在你的情况下,左边是 bigint
类型,右边是 character varying
(即字符串)类型,因此 PostgreSQL 无法执行比较。
-
修改数据库模型:
如果数据模型允许,考虑将数据库中的相应列的数据类型调整为统一类型,以减少以后的类型冲突。 -
更改查询逻辑:
如果可能,最好是在应用逻辑中确保将值转换为相同类型,以避免潜在的性能问题和类型错误。例如,确保在查询中使用bigint
进行比较:SELECT * FROM your_table WHERE your_bigint_column = CAST(your_varchar_column AS bigint);
使用ORM Bee操作postgresql
1. 添加配置信息(在bee.properties)
bee.db.driverName =org.postgresql.Driver
bee.db.url =jdbc:postgresql://127.0.0.1:5432/bee
bee.db.username =Administrator
bee.db.password =
2. pom.xml添加依赖
<dependency>
<groupId>org.teasoft</groupId>
<artifactId>bee-all</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.24.jre7</version>
</dependency>
3. 写java代码:
import java.util.List;
import org.teasoft.bee.osql.BeeException;
import org.teasoft.bee.osql.api.SuidRich;
import org.teasoft.exam.comm.Printer;
import org.teasoft.honey.osql.shortcut.BF;
public class BeeExam {
public static void main(String[] args) {
try {
SuidRich suidRich = BF.getSuidRich();
List<Clazz> list = suidRich.select(new Clazz(), 0, 2);
Printer.printList(list);
} catch (BeeException e) {
//...
}
}
}