Remove wrong logical error

When using ranges such as `(0 BETWEEN 1 AND 2)` the AST is
something like `(0 >= 1 AND 0 <= 2)`.

In the TemplateStructure we sort the tokens by the begin of them,
where both 0s share the original same token position. Thus, we
shouldn't ensure that the token position is monotonically increasing.
This commit is contained in:
Pablo Marcos 2024-09-30 11:48:48 +00:00
parent 9c83eb95de
commit e0d05bbadc
3 changed files with 14 additions and 3 deletions

View File

@ -331,9 +331,6 @@ ConstantExpressionTemplate::TemplateStructure::TemplateStructure(LiteralsInfo &
for (size_t i = 0; i < replaced_literals.size(); ++i)
{
const LiteralInfo & info = replaced_literals[i];
if (info.literal->begin.value() < prev_end)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot replace literals");
while (prev_end < info.literal->begin.value())
{
tokens.emplace_back(prev_end->begin, prev_end->size());

View File

@ -0,0 +1,13 @@
CREATE TABLE my_table (
str String,
) ORDER BY str;
INSERT INTO my_table VALUES
(
CASE WHEN
(0 BETWEEN 0 AND 2) THEN 'ok' ELSE
'wat'
END
);
SELECT * FROM my_table;