mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 14:16:54 +00:00
Labels early access features and hides features we aren't documenting yet. **Early access label:** Functions (4 pages, plus the GPU refresh, checkpointing and adaptive execution pages), Secrets (3 pages), Tiered Index Cache, Blob V2, and merge insert, which is labelled for Enterprise only. Two sidebar titles are shorter so the tag fits. **Hidden:** branching, JSON columns and geospatial. - The JSON functions page and the agent branch-experiments tutorial go in `.mintignore`. - `tables/branching` stays reachable but out of the nav, as #4859 left it, because SDK error messages link to it. - Other pages' mentions of these features become draft comments, so they're easy to restore. **Secrets page:** drops references to manual KMS setup, which the control plane handles. It keeps the encryption-at-rest facts, states the Azure value-size limit inline, and points a 501 error to support.
162 lines
4.8 KiB
Plaintext
162 lines
4.8 KiB
Plaintext
---
|
|
title: "Scalar functions"
|
|
sidebarTitle: "Scalar Functions"
|
|
description: "The per-row function set: math, string, regex, date/time, array, struct, and what Lance adds."
|
|
icon: calculator
|
|
keywords: ["scalar functions", "string functions", "math functions", "regex", "array functions"]
|
|
availability:
|
|
embedded: unavailable
|
|
enterprise: available
|
|
---
|
|
|
|
Functions that take a value and return a value, one row at a time. The set is
|
|
based on DataFusion's registration plus Lance and deployment-specific
|
|
functions. The names below are selected examples, not an exhaustive catalog
|
|
for every deployment. Availability depends on the deployed version and build.
|
|
|
|
For per-group functions see [Aggregation](/sql/dql/aggregation); for per-window,
|
|
[Window functions](/sql/dql/window).
|
|
|
|
## Math {#math}
|
|
|
|
```text
|
|
abs ceil floor round trunc signum power sqrt cbrt exp
|
|
ln log log2 log10 factorial gcd lcm pi random nanvl
|
|
isnan iszero cot degrees radians to_degrees to_radians
|
|
sin cos tan asin acos atan atan2
|
|
sinh cosh tanh asinh acosh atanh
|
|
```
|
|
|
|
## String {#string}
|
|
|
|
```text
|
|
ascii bit_length btrim chr concat concat_ws contains ends_with
|
|
starts_with levenshtein lower upper ltrim rtrim octet_length
|
|
repeat replace split_part to_hex uuid
|
|
```
|
|
|
|
Unicode-aware variants:
|
|
|
|
```text
|
|
character_length find_in_set initcap left right lpad rpad
|
|
reverse strpos substr substr_index substring translate
|
|
```
|
|
|
|
<Note>
|
|
For keyword matching on a text column, [`contains_tokens`](/sql/dql/contains-tokens)
|
|
is index-accelerated where `contains` and `LIKE` are not.
|
|
</Note>
|
|
|
|
## Regular expressions {#regex}
|
|
|
|
```text
|
|
regexp_count regexp_instr regexp_like regexp_match regexp_replace
|
|
```
|
|
|
|
## Date and time {#datetime}
|
|
|
|
```text
|
|
current_date current_time date_bin date_part date_trunc
|
|
from_unixtime to_unixtime make_date make_time to_char
|
|
to_date to_time to_local_time
|
|
```
|
|
|
|
`date_bin` is the one worth knowing for analytics: it buckets timestamps into
|
|
fixed-width intervals, which is how you build a time series without a
|
|
self-join.
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
SELECT date_bin(INTERVAL '1 hour', created_at) AS hour, count(*)
|
|
FROM events
|
|
GROUP BY hour
|
|
ORDER BY hour
|
|
```
|
|
</CodeGroup>
|
|
|
|
## Arrays and maps {#arrays}
|
|
|
|
```text
|
|
make_array array_has array_filter array_transform array_any_match
|
|
array_compact array_normalize array_slice arrays_zip cardinality
|
|
flatten range generate_series
|
|
```
|
|
|
|
```text
|
|
map map_keys map_values map_entries map_extract
|
|
```
|
|
|
|
Distance functions over arrays: `cosine_distance`, `distance`,
|
|
`exact_distance`, `inner_product`. Only `distance` and `exact_distance`
|
|
take an options string, and only `distance` can plan as vector search; see
|
|
[Vector distance functions](/sql/dql/vector-distance).
|
|
|
|
## Structs and fields {#structs}
|
|
|
|
```text
|
|
named_struct get_field coalesce nullif nvl nvl2 greatest least
|
|
union_extract union_tag
|
|
```
|
|
|
|
## Crypto and encoding {#crypto}
|
|
|
|
```text
|
|
digest md5 sha224 sha256 sha384 sha512 encode decode
|
|
```
|
|
|
|
## Type functions {#type}
|
|
|
|
```text
|
|
arrow_cast arrow_try_cast arrow_typeof arrow_field arrow_metadata
|
|
with_metadata version
|
|
```
|
|
|
|
Use `arrow_typeof` to inspect the Arrow data type of a column or expression:
|
|
|
|
<CodeGroup>
|
|
```sql SQL icon="database"
|
|
SELECT arrow_typeof(vector) FROM documents LIMIT 1
|
|
-- FixedSizeList(Field { name: "item", data_type: Float32, .. }, 1536)
|
|
```
|
|
</CodeGroup>
|
|
|
|
`arrow_cast` casts to an Arrow type by name, reaching types SQL has no spelling
|
|
for. See [Data types](/sql/data-types).
|
|
|
|
## What Lance adds {#lance}
|
|
|
|
These are registered by Lance on top of DataFusion's set, each with its own
|
|
reference page:
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| [`contains_tokens`](/sql/dql/contains-tokens) | index-accelerated keyword predicate, usable in `WHERE` |
|
|
| [`ivf_partition`](/sql/dql/ivf-partition) | assign each row to its trained IVF index partition |
|
|
| [`blob_descriptor`](/sql/dql/blob-descriptor) | a BlobV2 column's payload location, without reading it |
|
|
|
|
{/*
|
|
Draft until JSON columns reach early access.
|
|
| [JSON accessors](/sql/dql/json-functions) | `json_get` and its typed variants, `json_extract`, and more |
|
|
*/}
|
|
|
|
{/*
|
|
Draft: geospatial queries and indexes are unsupported in LanceDB Enterprise.
|
|
|
|
### Geospatial {#geo}
|
|
|
|
<Warning>
|
|
Lance defines `st_*` functions on GeoArrow, but they sit behind a build feature
|
|
**LanceDB does not ship**. Calling one returns an error naming the missing
|
|
feature rather than an unknown-function error, and the spatial index is gated
|
|
the same way.
|
|
</Warning>
|
|
*/}
|
|
|
|
## Additional scalar functions {#escape-hatch}
|
|
|
|
SQL queries can call functions registered with the server, including functions
|
|
not listed on this page. Consult
|
|
[DataFusion's scalar function reference](https://datafusion.apache.org/user-guide/sql/scalar_functions.html)
|
|
for version 54. Functions documented for a newer DataFusion release may not be
|
|
available in your LanceDB Enterprise version.
|