BETWEEN¶
Description¶
The BETWEEN clause retrieves all versions of records committed within a specified time interval [date1, date2]. Unlike AS OF (which returns only one snapshot version per row), BETWEEN can return multiple historical versions for each row that was modified during the window.
Syntax¶
(See the Syntax Notation Guide for notation rules).
Basic syntax¶
Full syntax¶
SELECT * | <columns>
FROM <table>
BETWEEN <date1> AND <date2>
[WHERE <condition>]
[ORDER BY <col> [ASC|DESC]]
[LIMIT <n>];
[!NOTE] In
SELECTstatements, the temporal clause andWHEREclause can appear in either order:
Boundary Semantics¶
- Start Boundary (
<date1>): Interpreted viadayStartMs. If no time is specified, it defaults to the beginning of the day (00:00:00.000). - End Boundary (
<date2>): Interpreted viadayEndMs. If no time is specified, it defaults to the end of the day (23:59:59.999).
This ensures that writing BETWEEN 2026-01-01 AND 2026-01-31 covers the entire calendar month of January from the first millisecond to the last.
How It Works¶
- Range Conversion: Converts both dates to millisecond timestamps
t1andt2. Ift1 > t2, an error is returned immediately. - Version Retrieval:
- For each primary key,
Table::selectBetween(pk, t1, t2)locates the first version committed at or beforet1(anchor). - Iterates through all subsequent versions whose
timestamp <= t2. - Skips records marked with the
deletedtombstone. - Filtering & Output: Applies any
WHEREcondition and column projections.
Examples¶
1. View All Row Changes Across a Quarter (employees)¶
2. Track Single Row Revisions (employees)¶
3. Combined with Semantic Search (documents)¶
SELECT * FROM documents
BETWEEN 2026-01-01 AND 2026-06-01
WHERE content SIMILAR TO "authentication timeout"
LIMIT 5;
Errors & Edge Cases¶
| Error Condition | Error Message |
|---|---|
| Start Date After End Date | BETWEEN range starts after it ends |