pub enum JsonFunc {
Show 28 variants
Json,
Jsonb,
Array,
ArrayB,
ArrayLength,
ErrorPosition,
Extract,
ExtractB,
Arrow,
ArrowShift,
Insert,
InsertB,
Object,
ObjectB,
Patch,
PatchB,
Pretty,
Remove,
RemoveB,
Replace,
ReplaceB,
Set,
SetB,
Type,
Valid,
Quote,
ArrayInsert,
ArrayInsertB,
}Expand description
A JSON built-in.
They are their own enum for the same reason the math functions are: they
share a rule none of the others has. Every one of them can fail - a document
that will not parse is an error and not a NULL - and every one of them cares
whether its arguments are already JSON, which is a property of the value
rather than of the expression. Folding them into ScalarFunc would push
both facts onto eighty functions that have neither.
The b spellings return the binary format rather than text. They are
separate identities rather than a flag because json_extract and
jsonb_extract differ in more than their output: the text form answers a
SQL value for a leaf and the binary form answers a document.
Variants§
Json
json(X)
Jsonb
jsonb(X)
Array
json_array(...)
ArrayB
jsonb_array(...)
ArrayLength
json_array_length(X[, P])
ErrorPosition
json_error_position(X)
Extract
json_extract(X, P, ...)
ExtractB
jsonb_extract(X, P, ...)
Arrow
The -> operator.
ArrowShift
The ->> operator.
Insert
json_insert(X, P, V, ...)
InsertB
jsonb_insert(X, P, V, ...)
Object
json_object(...)
ObjectB
jsonb_object(...)
Patch
json_patch(T, P)
PatchB
jsonb_patch(T, P)
Pretty
json_pretty(X[, indent])
Remove
json_remove(X, P, ...)
RemoveB
jsonb_remove(X, P, ...)
Replace
json_replace(X, P, V, ...)
ReplaceB
jsonb_replace(X, P, V, ...)
Set
json_set(X, P, V, ...)
SetB
jsonb_set(X, P, V, ...)
Type
json_type(X[, P])
Valid
json_valid(X[, flags])
Quote
json_quote(X)
ArrayInsert
json_array_insert(X, P, V, ...)
ArrayInsertB
jsonb_array_insert(X, P, V, ...)
Implementations§
Source§impl JsonFunc
impl JsonFunc
Sourcepub fn arity(self) -> (usize, usize)
pub fn arity(self) -> (usize, usize)
Returns how many arguments the function takes, as (least, most).
usize::MAX as the upper bound means “any number”, which the editing
functions further restrict to an odd count in
JsonFunc::arity_ok - a rule a pair of bounds cannot express.
Sourcepub fn arity_ok(self, count: usize) -> bool
pub fn arity_ok(self, count: usize) -> bool
Returns whether an argument count is legal for this function.
Sourcepub fn first_argument_is_a_document(self) -> bool
pub fn first_argument_is_a_document(self) -> bool
Returns whether this function’s first argument names a document to be read, rather than a value to be embedded or quoted.
The distinction an executor’s document-cache optimisation needs: it
may only substitute a pre-parsed JSONB blob for the first argument
when that argument is the document a call reads, such as X in
json_extract(X, P). json_array, json_object and json_quote
take that same position as a value - one that merely happens to
look like JSON is still meant to be embedded or quoted as a string,
per the subtype rule this module’s own doc comment states. Handing
them a blob instead answered “JSON cannot hold BLOB values” for a
perfectly ordinary unmarked string, which is what
json_array('[1]') did before this existed. Valid reads its
argument as a document too, but is excluded by its caller for the
unrelated reason that substituting a re-encoded blob changes what its
flags answer about the original text.