Skip to content

BETWEEN in expression index causes error on INSERT #5554

@LeMikaelF

Description

@LeMikaelF

Description

BETWEEN expressions in expression index columns are accepted at CREATE INDEX time but cause an error on INSERT. The SELECT path works correctly but the INSERT path fails to rewrite the BETWEEN expression.

Reproducer

CREATE TABLE t(a INTEGER, b INTEGER);
CREATE INDEX idx ON t(a BETWEEN 1 AND 10);
INSERT INTO t VALUES(5, 5);
-- Turso: Parse error: BETWEEN expression should have been rewritten in optmizer
-- SQLite: succeeds, inserts row

Error Message

Parse error: BETWEEN expression should have been rewritten in optmizer

core/translate/index.rs - validate_index_expression has a _ => {} catch-all that lets Expr::Between through at CREATE INDEX time. On INSERT, rewrite_index_expr_for_insertion does not call rewrite_between_expr, so translate_expr hits the BETWEEN case and bails. The SELECT path (emit_index_column_value_from_cursor) uses bind_and_rewrite_expr which does rewrite BETWEEN correctly.


This issue brought to you by Mikaël and Claude Code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    correctnessindexesnot-for-botsqlrightbugs found using SQLRight (https://github.com/PSU-Security-Universe/sqlright)Ï

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions