java - 无法在本机查询中使用“:”作为分隔符
问题描述
使用“:”作为分隔符将时间与日期分开。当我们在 sql 中运行查询时,它的工作原理。当 JPA 附带时,jpa 认为这个“:”分隔符作为命名参数,如何克服这个问题。
询问:
select (case when SPLIT_PART(
SPLIT_PART(inq.suggest_time::text, ' ', 2),
':', 1
)::int <= 10 and
SPLIT_PART(
SPLIT_PART(inq.suggest_time::text, ' ', 2),
':', 2
)::int < 30
then CONCAT(
(SPLIT_PART(
SPLIT_PART(inq.suggest_time::text, ' ', 1),
'-', 1
)::int)::text,
'-',
(SPLIT_PART(
SPLIT_PART(inq.suggest_time::text, ' ', 1),
'-', 2
)::int)::text,
'-',
(SPLIT_PART(
SPLIT_PART(inq.suggest_time::text, ' ', 1),
'-', 3
)::int + 1)::text)
else (SPLIT_PART(inq.suggest_time::text, ' ', 1))::text
end) as dateValue,
count(inq.suggest_time )
from inquiry_table inq
where inq.assigned_to= 63
and (inq.suggest_time is not null)
and inq.inquiry_status IN (select ld.lookup_detail_id
from lookup_detail ld
where ld.lookup_detail IN ('New','In Process'))
group by dateValue
ORDER BY dateValue;
应用程序错误:
Caused by: org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.hibernate.QueryException: Not all named parameters have been set: [:text, :int] [select (case when SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 2), ':', 1)::int <= 10 and SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 2), ':', 2)::int < 30 then CONCAT((SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 1)::int)::text, '-',(SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 2)::int)::text, '-',(SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 3)::int + 1)::text) else (SPLIT_PART(inq.suggest_time::text, ' ', 1))::text end) as dateValue,count(inq.suggest_time ) from inquiry inq where inq.assigned_to= 63 and (inq.suggest_time is not null) and inq.inquiry_status IN (select ld.lookup_detail_id from lookup_detail ld where ld.lookup_detail IN ('New','In Process')) group by dateValue ORDER BY dateValue]
解决方案
将 ::text 和 ::int 中的 :: 转义,如下所示:
\\:\\:text
\\:\\:int
推荐阅读
- git - 如何在git中的多个分支之间同步
- eclipse-cdt - 液晶显示旧数据和新数据
- facebook-graph-api - 在没有 manage_pages 权限的情况下从 facebook graph API 获取 instagram ID
- reactjs - Meteor 方法如何返回结果?
- angular - 获取 API 响应中的特定对象
- firefox - 如何在 Robot Framework 上打开 Firefox 53
- plugins - Shopify 中使用的插件是什么?
- python - python - 如何将列设置为DataFrame中的索引
- node.js - 如何在信使欢迎屏幕上添加按钮?
- django - Django websockets 身份验证