【发布时间】:2011-01-17 10:32:37
【问题描述】:
我对如何创建包含冒号的 SQL 语句感到困惑。我正在尝试创建一个视图并且我正在使用(注意双冒号):
create view MyView as (
SELECT
tableA.colA as colA,
tableB.colB as colB,
round(tableB.colD / 1024)::numeric, 2) as calcValue,
FROM
tableA, tableB
WHERE
tableA.colC = 'someValue'
);
这是一个 postgres 查询,我不得不使用双冒号 (::) 才能正确运行该语句。
然后我通过上面的语句传递:
s.createSQLQuery(myQuery).executeUpdate();
我得到一个:
Exception in thread "main" org.hibernate.exception.DataException: \
could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.convert(\
SQLStateConverter.java:102)
... more stacktrace...
我的上述语句的输出更改为(注意问号):
create view MyView as (
SELECT
tableA.colA as colA,
tableB.colB as colB,
round(tableB.colD / 1024)?, 2) as calcValue,
FROM
tableA, tableB
WHERE
tableA.colC = 'someValue'
);
显然,hibernate 将我的冒号与命名参数混淆了。
有没有办法转义冒号(谷歌建议提到单个冒号被转义为双冒号不起作用)或运行此语句的另一种方式?
谢谢。
【问题讨论】:
标签: hibernate postgresql escaping