hsqldb 中的间隔格式异常无效,但查询在 Postgres 中有效
Posted
技术标签:
【中文标题】hsqldb 中的间隔格式异常无效,但查询在 Postgres 中有效【英文标题】:Invalid interval format exception in hsqldb but query works in Postgres 【发布时间】:2018-06-07 07:17:56 【问题描述】:我正在 postgresql 中运行查询。它在 psql 中运行良好,但出于单元测试的目的,我创建了一个内存 HSQLDB 并在其中执行了相同的查询。但是会抛出“Invalid interval format”异常。由于我是 hsqldb 新手,所以我无法找出问题的根本原因。
查询:
INSERT INTO microbatch_redrive
SELECT mii.*,(to_char(CURRENT_TIMESTAMP ,'yyyy-mm-ddThh:mi:ss.msZ')) FROM
(SELECT * FROM
( SELECT mi.*,me.extractid FROM
(SELECT * FROM microbatch_info WHERE
((numattempts<= $maxNumOfAttempts)
AND (starttime>= '$starttime')
AND (starttime<= '$endtime')))
AS mi LEFT OUTER JOIN microbatch_extract_info AS me ON mi.microbatchid = me.microbatchid)
AS mime WHERE((mime.raverunstatus='SUCCEEDED' AND mime.extractid is null)
OR (mime.starttime < to_char(CURRENT_TIMESTAMP,'yyyy-mm-ddThh:mi:ss.msZ') AND mime.raverunstatus='NOT_STARTED')
OR (mime.raverunstatus = 'FAILED')
OR (mime.raverunstatus='STARTED' AND mime.starttime< (to_char(CURRENT_TIMESTAMP - INTERVAL '1 hour' * $extractTimeIntervalInHour,'yyyy-mm-ddThh:mi:ss.msZ')))
)
) AS mii LEFT OUTER JOIN
(SELECT microbatchid FROM microbatch_redrive WHERE raverunstatus='REDRIVE_SUCCEEDED') AS mr ON mii.microbatchid=mr.microbatchid WHERE mr.microbatchid IS NULL;
错误:
Caused by: org.hsqldb.HsqlException: data exception: invalid interval format
[junit] at org.hsqldb.error.Error.error(Unknown Source)
[junit] at org.hsqldb.error.Error.error(Unknown Source)
[junit] at org.hsqldb.types.IntervalType.getIntervalType(Unknown Source)
[junit] at org.hsqldb.ParserBase.readIntervalType(Unknown Source)
[junit] at org.hsqldb.ParserBase.readDateTimeIntervalLiteral(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSimpleValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readSQLFunction(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readFunction(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readColumnOrFunctionExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSimpleValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadRowElementList(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadRowOrCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadRowValuePredicand(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadPredicateRightPart(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadRowElementList(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanPrimaryOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanTestOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanFactorOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanTermOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanPrimaryOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanTestOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanFactorOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanTermOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadBooleanValueExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readWhereGroupHaving(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSubqueryTableBody(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSubqueryTableBody(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadTableSubqueryOrNull(Unknown Source)
[junit] at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
[junit] at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
[junit] at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
[junit] at org.hsqldb.ParserCommand.compilePart(Unknown Source)
[junit] at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
[junit] at org.hsqldb.Session.executeDirectStatement(Unknown Source)
[junit] at org.hsqldb.Session.execute(Unknown Source)
提前致谢。
【问题讨论】:
【参考方案1】:INTERVAL '1 hour'
是 Postgres 特定的区间语法。
在标准 SQL 中,您需要:INTERVAL '1' hour
,它也受 HSQLDB 支持(如果您需要适用于这两种产品的语句,则还支持 Postgres)。
所以完整的表达式应该是:
CURRENT_TIMESTAMP - INTERVAL '1' hour * $extractTimeIntervalInHour
【讨论】:
谢谢..完美工作:)以上是关于hsqldb 中的间隔格式异常无效,但查询在 Postgres 中有效的主要内容,如果未能解决你的问题,请参考以下文章
国际化时django.po中的msgstr =“”为中文时,django-admin.py compilemessages 出错:无效的多字节序列
SQLSyntaxErrorException:由于 HSQLDB 中的“COALESCE”导致的数据类型异常