mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-31 15:56:52 +00:00
## Summary - Complete the SQL reference: `ATTACH DATABASE`, the `CHANGES` clause, and `dedupe()`/`duplicate_pairs()` (verified against current sophon source; these were recently renamed from `vector_dedup`/`vector_duplicate_pairs`). Fix the blob-column default-projection claim and add the previously undocumented `blob_descriptor()`. - Enrich the gated Functions draft (still `.mintignore`'d, pre-release): chained Functions over blob outputs, GPU-produced blobs, Secrets, multi-input/output binding, `code=[module]` packaging. - Upgrade the materialized-view and computed-column auto-refresh drafts with precise, verified catch-up semantics, and add the missing `ALTER MATERIALIZED VIEW` / `CREATE ... WITH(...)` sections (also gated — the automatic-refresh scheduler is still dev/staging-only). - Thread one running example (video frames → GPU extract/caption → dedup → auto-refreshing materialized view) through Functions, materialized views, and the LeRobotDataset integration guide instead of a separate tutorial. - Rename "LanceDB OSS"/"OSS" to "LanceDB Embedded"/"Embedded" throughout (52 files); activate the existing availability-comparison mechanism on `basics/offerings.mdx` for a full feature-by-feature comparison table.
87 lines
3.0 KiB
Plaintext
87 lines
3.0 KiB
Plaintext
---
|
|
title: "Operators and literals"
|
|
sidebarTitle: "Operators"
|
|
description: "Comparison, logical and arithmetic operators, literals, and precedence."
|
|
icon: plus-minus
|
|
keywords: ["operators", "literals", "precedence", "null", "cast", "interval"]
|
|
availability:
|
|
embedded: unavailable
|
|
enterprise: available
|
|
---
|
|
|
|
LanceDB uses DataFusion's SQL operators. This page describes comparison,
|
|
logical and arithmetic operators, literal values, type conversions and
|
|
operator precedence.
|
|
|
|
## Comparison {#comparison}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| `=` `!=` `<>` `<` `<=` `>` `>=` | ordinary comparison |
|
|
| `IS NULL` / `IS NOT NULL` | null test (`= NULL` is never true) |
|
|
| `IS DISTINCT FROM` | comparison that treats null as a value |
|
|
| `BETWEEN a AND b` | inclusive range |
|
|
| `IN (...)` | set membership |
|
|
| `LIKE` / `ILIKE` | pattern match, `%` and `_` |
|
|
| `~` `~*` `!~` | regular expression match |
|
|
|
|
<Note>
|
|
For keyword matching on a text column, [`contains_tokens`](/sql/scalar-functions#contains-tokens)
|
|
is index-accelerated where `LIKE` is not. Reach for `LIKE` only when you need
|
|
its wildcard semantics.
|
|
</Note>
|
|
|
|
## Logical {#logical}
|
|
|
|
`AND`, `OR`, `NOT`. Three-valued: a comparison against null is **unknown**, and
|
|
`NOT unknown` is still unknown. A `WHERE` clause keeps only rows where the
|
|
predicate is true, so unknown behaves like false there, but not inside `NOT
|
|
IN`, which is the usual place this bites. See
|
|
[Subqueries](/sql/dql/subqueries#in-exists).
|
|
|
|
## Arithmetic {#arithmetic}
|
|
|
|
`+` `-` `*` `/` `%`, with the usual precedence. String concatenation is `||`.
|
|
|
|
<Warning>
|
|
Arithmetic over a vector column is **list** arithmetic, not scalar arithmetic:
|
|
a vector is a `FixedSizeList<Float32>`. When the operation you want is a
|
|
similarity comparison, use [vector search](/search/vector-search); whether SQL
|
|
can express it [depends on the Enterprise server version](/basics/sql#no-vector-sql).
|
|
</Warning>
|
|
|
|
## Literals {#literals}
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| String | `'text'`, with a doubled quote to escape: `'it''s'` |
|
|
| Number | `42`, `3.14` |
|
|
| Boolean | `TRUE`, `FALSE` |
|
|
| Null | `NULL` |
|
|
| Date / timestamp | `DATE '2026-01-01'`, `TIMESTAMP '2026-01-01 12:00:00'` |
|
|
| Interval | `INTERVAL '7 days'` |
|
|
| Array | `[1, 2, 3]` |
|
|
|
|
Identifiers are quoted with double quotes when they need to be (a reserved word
|
|
or a name with mixed case): `SELECT "order" FROM "MyTable"`.
|
|
|
|
## Casting {#casting}
|
|
|
|
```sql
|
|
SELECT CAST(identifier AS VARCHAR) AS with_cast, identifier::VARCHAR AS with_colons
|
|
FROM documents
|
|
```
|
|
|
|
Both forms work. Give each its own alias when one projection uses both: they
|
|
produce the same expression name, and a projection refuses two columns with
|
|
one name. `TRY_CAST` returns null instead of erroring on a value that
|
|
will not convert, which is the one to use over a column you do not control.
|
|
|
|
## Precedence {#precedence}
|
|
|
|
Highest to lowest: `::` → unary `-` → `* / %` → `+ -` → `||` → comparison →
|
|
`IS` → `NOT` → `AND` → `OR`.
|
|
|
|
Parenthesize anything mixing `AND` and `OR`. `a OR b AND c` is `a OR (b AND c)`,
|
|
which is rarely what was meant.
|