hsqldb 中的无效间隔格式异常,但查询在 Postgres 中有效
Invalid interval format exception in hsqldb but query works in Postgres
我是 运行 postgresql 中的一个查询。它在 psql 中运行良好,但出于单元测试的目的,我在内存中创建了一个 HSQLDB 并在其中执行了相同的查询。但是 "Invalid interval format" 异常是 thrown.Since 我是 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)
提前致谢。
INTERVAL '1 hour'
是 Postgres 特定的间隔语法。
在标准 SQL 中,您需要:INTERVAL '1' hour
HSQLDB 也支持(如果您需要适用于这两种产品的语句,还支持 Postgres)。
所以完整的表达式应该是:
CURRENT_TIMESTAMP - INTERVAL '1' hour * ${extractTimeIntervalInHour}
我是 运行 postgresql 中的一个查询。它在 psql 中运行良好,但出于单元测试的目的,我在内存中创建了一个 HSQLDB 并在其中执行了相同的查询。但是 "Invalid interval format" 异常是 thrown.Since 我是 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)
提前致谢。
INTERVAL '1 hour'
是 Postgres 特定的间隔语法。
在标准 SQL 中,您需要:INTERVAL '1' hour
HSQLDB 也支持(如果您需要适用于这两种产品的语句,还支持 Postgres)。
所以完整的表达式应该是:
CURRENT_TIMESTAMP - INTERVAL '1' hour * ${extractTimeIntervalInHour}