Skip to content

Incorrect error parsing SELECT of constant expression with subtraction arithmetic #165

@cdmh

Description

@cdmh

Using a constant expression with a subtraction in a SELECT statement fails incorrectly. All of these statements cause error syntax error, unexpected INTVAL, expecting end of file.

SELECT 6-2;
SELECT 6-2-1;
SELECT 6+5/8*4-9;

However, other arithmetic operators work, including unary minus

SELECT 1.5*2.5;
SELECT 1.5*2.5*2;
SELECT 1+2;
SELECT 1+2+3;
SELECT 6/2;
SELECT 6/2/2;
SELECT -6;
SELECT -6+3;
SELECT -6.5;
SELECT -6.5+3;

Example:

hsql::SQLParserResult parser_result;
if (!(hsql::SQLParser::parse("SELECT 6-2;", &parser_result)  &&  parser_result.isValid()))
{
    std::ostringstream oss;
    oss << sql << '\n'
        << std::setw(parser_result.errorColumn()+7) << "^-----\n"
        << parser_result.errorMsg() << "\n";

    auto error = oss.str();
    throw std::runtime_error(error);
}

yields:

SELECT 6-2;
        ^-----
syntax error, unexpected INTVAL, expecting end of file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions