java - 将 postgres bytea 与字符串进行比较时,Spring JDBC 抛出异常
问题描述
我有一张这样的桌子
create table tabl(id bytea, val text);
&这样的查询
select * from tabl where id='foo';
当我在 PSQL 或 pgAdmin 中执行此查询时,它可以工作
但是当 Spring JdbcTemplate 执行相同的查询时,它会引发异常
exception is org.postgresql.util.PSQLException: ERROR: operator does not exist: bytea = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Java 代码如下所示:
jdbcTemplate.queryForObject("select val from tabl where id=?", new Object[] {id}, String.class)
虽然我知道我可以通过使用decode
函数来解决这个问题
jdbcTemplate.queryForObject("select val from tabl where id=decode(?,'escape')", new Object[] {id}, String.class)
似乎 Postgres 会自动将文本转换为 bytea 进行比较,但为什么用 spring jdbc 抛出异常呢?
谢谢
解决方案
推荐阅读
- flutter - Flutter build 发布 AndroidX 不兼容问题
- java - 通过java运行Keras python脚本导致脚本中途突然停止
- mysql - 错误!在 MacOS Mojave 上使用 Homebrew 安装 MySQL 5.6 后服务器退出而不更新 PID 文件
- lua - 有没有办法从罗技 lua 日志控制台获取数据?
- python-3.x - 一条线解决
- angular - Angular 8 获取 BehaviorSubject 的值返回 null
- google-analytics - 谷歌分析会话计数问题
- java - 使用 BufferedReader 和 ScheduledExecutor 记录日志
- python - 遍历列表以查找列表元素的出现
- vue.js - 如何在保存时自动设置 vscode 格式的 Vue 模板?