hsqldb中的间隔格式异常无效,但查询在Postgres中有效

时间:2018-06-07 07:17:57

标签: sql hsqldb intervals

我在postgresql中运行查询。它在psql中工作正常,但出于单元测试的目的,我创建了一个内存HSQLDB并在其中执行相同的查询。但是抛出了“无效的间隔格式”异常。因为我是hsqldb的新手,所以我无法找出问题的根本原因。

QUERY:

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 个答案:

答案 0 :(得分:1)

INTERVAL '1 hour'是Postgres特定的区间语法。

在标准SQL中,您需要:INTERVAL '1' hour,HSQLDB也支持它(如果您需要一个适用于这两种产品的语句,则需要Postgres)。

所以完整的表达应该是:

CURRENT_TIMESTAMP - INTERVAL '1' hour * ${extractTimeIntervalInHour}