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