sqlparser/datatypes.cpp
// INTERVAL in Oracle, PostgreSQL, Informix, Netezza
INTERVAL in Oracle, PostgreSQL, Informix, Netezza
INTERVAL in Oracle PostgreSQL Informix Netezza
bool SqlParser::ParseIntervalType(Token *name)
{
    if(name == NULL)
        return false;
    if(name->Compare("INTERVAL", L"INTERVAL", 8) == false)
        return false;
	STATS_DECL
 	STATS_ITM_DECL
    DTYPE_STATS(name)
    bool start = false;
    Token *first_unit = GetNextToken();
    Token *first_year = NULL;
    Token *first_month = NULL;
    Token *first_day = NULL;
    Token *first_hour = NULL;
    Token *first_minute = NULL;
    Token *first_second = NULL;
    Token *first_fraction = NULL;
    Token *to = NULL;
    Token *second_unit = NULL;
    if(Token::Compare(first_unit, "YEAR", L"YEAR", 4) == true)
    {
        first_year = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "MONTH", L"MONTH", 5) == true)
    {
        first_month = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "DAY", L"DAY", 3) == true)
    {
        first_day = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "HOUR", L"HOUR", 4) == true)
    {
        first_hour = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "MINUTE", L"MINUTE", 6) == true)
    {
        first_minute = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "SECOND", L"SECOND", 6) == true)
    {
        first_second = first_unit;
        start = true;
    }
    else
    if(Token::Compare(first_unit, "FRACTION", L"FRACTION", 8) == true)
    {
        first_fraction = first_unit;
        start = true;
    }
    else
        PushBack(first_unit);
    Token *open = NULL;
    Token *close = NULL;
    if(start == true)
    {
        open = GetNextCharToken('(', L'(');
        if(open != NULL)
        {
             (void) GetNextNumberToken();
            close = GetNextCharToken(')', L')');
        }
        to = GetNextWordToken("TO", L"TO", 2);
        if(to != NULL)
            second_unit = GetNextToken();
    }
    Token *open2 = GetNextCharToken('(', L'(');
    Token *scale = NULL;
    Token *close2 = NULL;
    if(open2 != NULL)
    {
        scale = GetNextNumberToken();
        close2 = GetNextCharToken(')', L')');
    }
    if(_target == SQL_ORACLE && _source != SQL_ORACLE)
    {
        if(start == false)
            Append(name, " DAY(5) TO SECOND", L" DAY(5) TO SECOND", 17);
        else
        if(to == NULL || Token::Compare(first_unit, second_unit) == true)
        {
            Token::Remove(name);
            Token::Remove(to, second_unit);
            Token::Change(first_unit, "NUMBER", L"NUMBER", 6);
            if(open == NULL)
            {		
                if(open2 != NULL)
                    Prepend(scale, "5,", L"5,", 2);
                else
                    Append(first_unit, "(5)", L"(5)", 3);
            }
        }
        else
        if(to != NULL && first_year == NULL)
        {
            Token::Change(first_unit, "DAY", L"DAY", 3);
            if(open == NULL)
                Append(first_unit, "(5)", L"(5)", 3);
            Token::Change(second_unit, "SECOND", L"SECOND", 6);
        }
    }
    else
    if(Target(SQL_SQL_SERVER, SQL_MARIADB, SQL_MYSQL) == true)
    {
        Token::Remove(first_unit, second_unit);
        Token::Remove(open2, close2);
        Token::Change(name, "VARCHAR(30)", L"VARCHAR(30)", 11);
        STATS_ITM_CONV_ERROR 
    }
    else
    if(_target == SQL_POSTGRESQL && _source != SQL_POSTGRESQL)
    {
        if(open != NULL)
            Token::Remove(open, close);
        if(Token::Compare(first_unit, second_unit) == true ||
            (Token::Compare(first_unit, "SECOND", L"SECOND", 6) == true &&
            Token::Compare(second_unit, "FRACTION", L"FRACTION", 8) == true))
            Token::Remove(to, second_unit);
        if(Token::Compare(first_unit, "FRACTION", L"FRACTION", 8) == true)
            Token::Change(first_unit, "SECOND", L"SECOND", 6);
        else
            if(Token::Compare(second_unit, "FRACTION", L"FRACTION", 8) == true)
                Token::Change(second_unit, "SECOND", L"SECOND", 6);
    }
    else
    if(_target == SQL_NETEZZA && _source != SQL_NETEZZA)
    {
        Token::Remove(first_unit, close);
        Token::Remove(to);
        Token::Remove(second_unit);
    }
    else
    if(_target == SQL_ESGYNDB && _source != SQL_ESGYNDB)
        STATS_ITM_CONV_NO_NEED
    DTYPE_DTL_STATS_L(name)
    return true;
}
bool SqlParser :: ParseIntervalType ( Token * name ) { if ( name == NULL ) return false ; if ( name -> Compare ( " " , L" " , 8 ) == false ) return false ; STATS_DECL STATS_ITM_DECL DTYPE_STATS ( name ) bool start = false ; Token * first_unit = GetNextToken ( ) ; Token * first_year = NULL ; Token * first_month = NULL ; Token * first_day = NULL ; Token * first_hour = NULL ; Token * first_minute = NULL ; Token * first_second = NULL ; Token * first_fraction = NULL ; Token * to = NULL ; Token * second_unit = NULL ; if ( Token :: Compare ( first_unit , " " , L" " , 4 ) == true ) { first_year = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 5 ) == true ) { first_month = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 3 ) == true ) { first_day = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 4 ) == true ) { first_hour = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 6 ) == true ) { first_minute = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 6 ) == true ) { first_second = first_unit ; start = true ; } else if ( Token :: Compare ( first_unit , " " , L" " , 8 ) == true ) { first_fraction = first_unit ; start = true ; } else PushBack ( first_unit ) ; Token * open = NULL ; Token * close = NULL ; if ( start == true ) { open = GetNextCharToken ( ' ' , L' ' ) ; if ( open != NULL ) { ( void ) GetNextNumberToken ( ) ; close = GetNextCharToken ( ' ' , L' ' ) ; } to = GetNextWordToken ( " " , L" " , 2 ) ; if ( to != NULL ) second_unit = GetNextToken ( ) ; } Token * open2 = GetNextCharToken ( ' ' , L' ' ) ; Token * scale = NULL ; Token * close2 = NULL ; if ( open2 != NULL ) { scale = GetNextNumberToken ( ) ; close2 = GetNextCharToken ( ' ' , L' ' ) ; } if ( _target == SQL_ORACLE && _source != SQL_ORACLE ) { if ( start == false ) Append ( name , " " , L" " , 17 ) ; else if ( to == NULL || Token :: Compare ( first_unit , second_unit ) == true ) { Token :: Remove ( name ) ; Token :: Remove ( to , second_unit ) ; Token :: Change ( first_unit , " " , L" " , 6 ) ; if ( open == NULL ) { if ( open2 != NULL ) Prepend ( scale , " " , L" " , 2 ) ; else Append ( first_unit , " " , L" " , 3 ) ; } } else if ( to != NULL && first_year == NULL ) { Token :: Change ( first_unit , " " , L" " , 3 ) ; if ( open == NULL ) Append ( first_unit , " " , L" " , 3 ) ; Token :: Change ( second_unit , " " , L" " , 6 ) ; } } else if ( Target ( SQL_SQL_SERVER , SQL_MARIADB , SQL_MYSQL ) == true ) { Token :: Remove ( first_unit , second_unit ) ; Token :: Remove ( open2 , close2 ) ; Token :: Change ( name , " " , L" " , 11 ) ; STATS_ITM_CONV_ERROR } else if ( _target == SQL_POSTGRESQL && _source != SQL_POSTGRESQL ) { if ( open != NULL ) Token :: Remove ( open , close ) ; if ( Token :: Compare ( first_unit , second_unit ) == true || ( Token :: Compare ( first_unit , " " , L" " , 6 ) == true && Token :: Compare ( second_unit , " " , L" " , 8 ) == true ) ) Token :: Remove ( to , second_unit ) ; if ( Token :: Compare ( first_unit , " " , L" " , 8 ) == true ) Token :: Change ( first_unit , " " , L" " , 6 ) ; else if ( Token :: Compare ( second_unit , " " , L" " , 8 ) == true ) Token :: Change ( second_unit , " " , L" " , 6 ) ; } else if ( _target == SQL_NETEZZA && _source != SQL_NETEZZA ) { Token :: Remove ( first_unit , close ) ; Token :: Remove ( to ) ; Token :: Remove ( second_unit ) ; } else if ( _target == SQL_ESGYNDB && _source != SQL_ESGYNDB ) STATS_ITM_CONV_NO_NEED DTYPE_DTL_STATS_L ( name ) return true ; }
INTERVAL in Oracle, PostgreSQL, Informix, Netezza
INTERVAL in Oracle PostgreSQL Informix Netezza
// Precision is optional in Oracle and Informix /*Token *precision */ // Second unit is optional in PostgreSQL // Scale is optional // Convert INTERVAL in PostgreSQL to INTERVAL DAY(5) TO SECOND in Oracle // When second unit is not specified (for PostgreSQL)  // or first unit is equal to second unit (for Informix) convert to NUMBER(5) in Oracle // If second unit is specified convert to INTERVAL DAY TO SECOND in Oracle, except INTERVAL YEAR TO MONTH // If precision is not specified for Informix // Convert to VARHCAR(30) in SQL Server, MySQL // Remove precision for PostgreSQL // When first unit is equal to second unit (for Informix) // or first unit is SECOND and second unit is FRACTION (for Informix) remove second unit in PostgreSQL // Change FRACTION in Informix to SECOND in PostgreSQL  // Netezza parser units but throws runtime errors // EsgynDB supports Oracle INTERVAL syntax