pub enum ScalarFunc {
Show 82 variants
Abs,
Char,
Coalesce,
Concat,
ConcatWs,
Glob,
Hex,
IfNull,
Iif,
Instr,
Length,
Like,
Likelihood,
Lower,
LTrim,
Max,
Min,
NullIf,
Quote,
Replace,
Round,
RTrim,
Sign,
Substr,
Trim,
TypeOf,
Unhex,
Unicode,
Upper,
ZeroBlob,
Printf,
OctetLength,
Random,
RandomBlob,
Changes,
TotalChanges,
LastInsertRowid,
SourceId,
Fts5SourceId,
Version,
VectorDistanceCos,
VectorDistanceL2,
VectorDot,
VectorDistanceL1,
VectorDistanceHamming,
VectorDistanceJaccard,
VectorDims,
VectorNorm,
VectorNormalize,
VectorQuantize,
VectorSlice,
VectorAdd,
VectorSubtract,
VectorMultiply,
VectorConcat,
GeopolyArea,
GeopolyBlob,
GeopolyJson,
GeopolySvg,
GeopolyWithin,
GeopolyContainsPoint,
GeopolyOverlap,
GeopolyDebug,
GeopolyBbox,
GeopolyXform,
GeopolyRegular,
GeopolyCcw,
Unknown,
Subtype,
Unistr,
UnistrQuote,
CompileOptionUsed,
CompileOptionGet,
Log,
LoadExtension,
Regexp,
SqlarCompress,
SqlarUncompress,
Offset,
RTreeDepth,
RTreeNode,
RTreeCheck,
}Expand description
A scalar built-in.
Variants§
Abs
abs(x)
Char
char(...)
Coalesce
coalesce(...)
Concat
concat(...)
ConcatWs
concat_ws(sep, ...)
Glob
glob(pattern, text)
Hex
hex(x)
IfNull
ifnull(a, b)
Iif
iif(a, b, c)
Instr
instr(haystack, needle)
Length
length(x)
Like
like(pattern, text[, escape])
Likelihood
likelihood(x, y), likely(x) and unlikely(x), which are no-ops.
Lower
lower(x)
LTrim
ltrim(x[, chars])
Max
max(a, b, ...), the scalar form.
Min
min(a, b, ...), the scalar form.
NullIf
nullif(a, b)
Quote
quote(x)
Replace
replace(text, from, to)
Round
round(x[, digits])
RTrim
rtrim(x[, chars])
Sign
sign(x)
Substr
substr(x, start[, length])
Trim
trim(x[, chars])
TypeOf
typeof(x)
Unhex
unhex(x[, chars])
Unicode
unicode(x)
Upper
upper(x)
ZeroBlob
zeroblob(n)
Printf
printf(format, ...) and format(format, ...)
OctetLength
octet_length(x)
Random
random()
RandomBlob
randomblob(n)
Changes
changes()
TotalChanges
total_changes()
LastInsertRowid
last_insert_rowid()
SourceId
sqlite_source_id()
Fts5SourceId
fts5_source_id()
Version
sqlite_version()
VectorDistanceCos
vector_distance_cos(a, b), the cosine distance between two vectors.
Not a SQLite function, and the first one this engine adds. pgvector
spells it a <=> b; the whole point of Phase 2’s Part 7 is that a
vector is a value a SELECT can order by, and an operator that is sugar
for a function needs the function to exist first. A vector is a blob of
little-endian f32, which is what inillucent_search already stores and
what vector_distance_l2 and vector_dot read too.
VectorDistanceL2
vector_distance_l2(a, b), the Euclidean distance between two vectors.
VectorDot
vector_dot(a, b), the dot product of two vectors.
Negated relative to pgvector’s <#>, which answers the negative inner
product so that a smaller number is a better match. This answers the dot
product itself, because a function named dot that returned its negative
would be a trap; the ordering sugar negates where it needs to.
VectorDistanceL1
l1_distance(a, b), the taxicab distance, spelled a <+> b.
VectorDistanceHamming
hamming_distance(a, b), how many components differ.
pgvector defines it over its bit type and spells it a <~> b. Here a
bit vector is the blob binary_quantize produces, and the distance is
the population count of the two blobs’ exclusive-or - which is the same
number, computed the same way, over the representation this engine has.
VectorDistanceJaccard
jaccard_distance(a, b), one minus the overlap, spelled a <%> b.
VectorDims
vector_dims(a), how many components a vector has.
VectorNorm
vector_norm(a), its Euclidean length.
VectorNormalize
l2_normalize(a), the same direction with length one.
VectorQuantize
binary_quantize(a), one bit per component: set when it is positive.
VectorSlice
subvector(a, start, count), a slice, counted from one.
VectorAdd
vector_add(a, b), component by component.
A function rather than +, and that is a compatibility choice rather
than a shortcut. pgvector can overload + because a vector is a
distinct type in PostgreSQL; here a vector is a blob, and SQLite says
that a blob in arithmetic is zero. Overloading the operator for every
blob would change the answer to x'00' + x'00' from 0 to a blob,
which is a difference every application that adds two blobs would see.
The operators were given back, on the one condition that keeps
both answers. a + b binds to this function when a side reads a
column declared VECTOR(n) - which is the same thing PostgreSQL is
using, a declared type - and stays SQLite’s arithmetic otherwise. So
x'00' + x'00' is still 0 and v + v over a vector column is a
vector.
VectorSubtract
vector_sub(a, b), component by component.
VectorMultiply
vector_mul(a, b), component by component.
VectorConcat
vector_concat(a, b), one vector after the other.
GeopolyArea
geopoly_area(P), the signed area a polygon encloses.
The geopoly surface is thirteen functions and one aggregate, and
they are listed here individually rather than folded into one
Geopoly(kind) variant because arity checking reads this enum: they
take one, two, three, four, seven and any number of arguments, and a
single variant could not say so.
GeopolyBlob
geopoly_blob(P), the stored form of a polygon.
GeopolyJson
geopoly_json(P), the GeoJSON form.
GeopolySvg
geopoly_svg(P, ...), an SVG <polyline> with the extra arguments
written into the tag.
GeopolyWithin
geopoly_within(P1, P2), whether the second is inside the first.
GeopolyContainsPoint
geopoly_contains_point(P, X, Y), where a point sits.
GeopolyOverlap
geopoly_overlap(P1, P2), how two polygons meet.
GeopolyDebug
geopoly_debug(X), which answers nothing.
It switches on the reference’s own tracing, which only exists in a build
made with GEOPOLY_ENABLE_DEBUG; in every other build it reads its
argument and returns nothing at all. That is what this does, and it is
registered because a name the reference resolves and this engine does
not is a difference an application can see.
GeopolyBbox
geopoly_bbox(P), the bounding box as a four-sided polygon.
GeopolyXform
geopoly_xform(P, A, B, C, D, E, F), an affine transform.
GeopolyRegular
geopoly_regular(X, Y, R, N), a regular polygon.
GeopolyCcw
geopoly_ccw(P), the same ring wound counter-clockwise.
Unknown
unknown(...), which answers NULL to anything.
SQLite registers it, lists it in function_list, and returns NULL from
it whatever it is given. It is here because a name the reference resolves
and this engine does not is a difference an application can see.
Subtype
subtype(x), the tag a function attached to its answer.
Unistr
unistr(x), which expands \uXXXX and \UXXXXXXXX escapes.
UnistrQuote
unistr_quote(x), quote() with the control characters escaped.
CompileOptionUsed
sqlite_compileoption_used(name)
CompileOptionGet
sqlite_compileoption_get(n)
Log
sqlite_log(code, message), which writes to the log and answers NULL.
LoadExtension
load_extension(path[, entry])
Regexp
regexp(pattern, subject), which is what X REGEXP Y calls.
SqlarCompress
sqlar_compress(X), a blob compressed if that makes it smaller.
The archive format’s own rule, and it is why this is not just a
compressor. A row of a .sqlar table holds either a zlib stream or
the raw bytes, and which one is decided by whichever is shorter; the
stored sz column is what tells the two apart on the way back. So a
value that does not compress is stored as it stands, and a value that is
not a blob at all is returned unchanged, type and all.
SqlarUncompress
sqlar_uncompress(Z, SZ), the inverse.
SZ is the size the row claims the content is. When it equals the
blob’s own length the blob is the content and is returned unchanged,
which is how the format says “this one was stored raw”.
Offset
sqlite_offset(X), where in the file the row holding X is.
The page, not the record, and that is the whole of the difference. SQLite reports the byte offset of the record a value would be read from, because a row there is one contiguous run of bytes. A leaf here is PAX: each column is its own run, so one row occupies several places on its page and there is no single offset for it. What is reported is the offset of the page, which is where the value is genuinely read from.
Folded to its answer by the physical pass, like rtreecheck, because it
is a question about a tree rather than about a value.
RTreeDepth
rtreedepth(X), the depth stored at the front of an R-Tree node.
RTreeNode
rtreenode(D, X), an R-Tree node rendered as a readable list.
RTreeCheck
rtreecheck(T), an integrity check over one R-Tree table.
Answered where the table is reachable, which is not here. A scalar is handed values and nothing else; this one is about a table, so the physical pass folds it to its answer while it still has the catalog, and what reaches the evaluator is already the text. Running once per preparation rather than once per row is also what it means: the argument is a table name, so the answer cannot vary down a column.