WHERE Clause¶
Description¶
The WHERE clause filters rows in SELECT, UPDATE, DELETE, and temporal statements (COMPARE, EVOLUTION, HISTORY, ROLLBACK). It supports relational comparison operators as well as semantic similarity search.
Syntax¶
(See the Syntax Notation Guide for notation rules).
Basic syntax¶
Full syntax¶
-- Relational comparison
WHERE <column> (= | != | < | <= | > | >=) <value>
-- Semantic search (SELECT only)
WHERE <semantic_col> SIMILAR TO "<query text>"
Supported comparison operators:
| Operator | Meaning | Applicable Data Types |
|---|---|---|
= |
Equal to | INT, FLOAT, STRING, BOOL |
!= |
Not equal to | INT, FLOAT, STRING, BOOL |
< |
Less than | INT, FLOAT, STRING |
<= |
Less than or equal to | INT, FLOAT, STRING |
> |
Greater than | INT, FLOAT, STRING |
>= |
Greater than or equal to | INT, FLOAT, STRING |
[!IMPORTANT]
SIMILAR TOis supported only inSELECTstatements, and only on columns declared with theSEMANTICmodifier inCREATE TABLE.
Language Rules & Constraints¶
1. Single Condition Only¶
MemoraDB supports exactly one condition per WHERE clause. Compound logical operations with AND or OR chains are not supported:
-- Valid
SELECT * FROM students WHERE gpa >= 3.5;
-- Invalid: compound conditions are not supported
SELECT * FROM students WHERE gpa >= 3.5 AND is_enrolled = true;
-- Parse Error
2. Boolean Type Comparisons¶
For BOOL columns, only = and != are valid. Relational ordering operators (<, <=, >, >=) evaluate to false for boolean fields.
Examples¶
1. Integer Comparison (students)¶
2. Floating-Point Comparison (students)¶
3. String Comparison (students)¶
4. Semantic Search (documents)¶
Errors & Edge Cases¶
| Error Condition | Error Message |
|---|---|
| Unknown Column | Unknown column '<col>' on table '<table>' |
| SIMILAR TO on Non-Semantic Column | Column '<col>' is not declared SEMANTIC, so SIMILAR TO can't be used on it |
| SIMILAR TO in DML | SIMILAR TO is only supported in SELECT ... WHERE on a SEMANTIC column |
| Invalid Operator | Expected a comparison operator (=, !=, <, <=, >, >=) but got ... |
Related Commands¶
SELECT— Querying with WHERE.UPDATE— Targeted updates.DELETE— Targeted deletions.SIMILAR TO— Semantic search reference.