postgresql - 如何修复 SQLException:错误:“:”位置或附近的语法错误:15?
问题描述
我想获取以下问题中提到的数据。
所以据此,我在 Postgresql 中执行以下查询,所以它工作正常。
select '00:00'::time + g.h * interval '1 hour',count(sv.id) as orders from generate_series(0, 23, 1) g(h) left join paymentvirtualization.summery_virtualizer sv on extract(hour from sv.last_updated) = g.h and date_trunc('day', sv.last_updated) = '2019-10-11' group by g.h order by g.h;
但我的问题是我希望它像 Spring Data JPA 本机查询一样执行。
@Query(
value = "select '00:00'::time + g.h * interval '1 hour',count(sv.id) as orders from generate_series(0, 23, 1) g(h) left join paymentvirtualization.summery_virtualizer sv on extract(hour from sv.last_updated) = g.h and date_trunc('day', sv.last_updated) = '2019-10-11' group by g.h order by g.h",
nativeQuery = true
)
List<Map<String, Integer>> getPaymentDistry();
如果我执行它,我会收到类似的错误
could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
有人能帮我一下吗?
谢谢,
解决方案
混淆层阻塞,::
因为它用于:
引入命名参数。通常,解决方案是改用符合标准的cast()
运算符。
select cast('00:00' as time) + g.h * interval '1 hour' ...
或者使用 Laurenz 建议的 ANSI 时间语法:
select time '00:00' + g.h * interval '1 hour' ...
推荐阅读
- sql - 如何获取具有位置的员工每天的最小和最大日期?
- tensorflow - 批处理结束后如何更改 Tensorflow 中的学习率?
- python - 在 python 包 install_requires 中指定“或”
- python - seaborn FacetGrid 垂直轴上的分层标签
- python - Python 到 C++ 通信失败
- python - 如何从 SymPy 中提取椭圆的中心坐标、高度、宽度和 phi 以绘制拟合椭圆?
- ignite - 如何为使用 Apache Ignite 的无状态服务挂载卷
- macos - 未加载库:在 Clion Editor 上执行 Valgrind 时 /usr/lib/libc++.1.dylib
- regex - HIVE - 从字符串列中获取所有匹配的文本
- c# - PDPSharp 图表位置和背景