Skip to main content

JsonFunc

Enum JsonFunc 

Source
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

Source

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.

Source

pub fn arity_ok(self, count: usize) -> bool

Returns whether an argument count is legal for this function.

Source

pub fn is_binary(self) -> bool

Returns whether the function answers the binary format.

Source

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.

Trait Implementations§

Source§

impl Clone for JsonFunc

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for JsonFunc

Source§

impl Debug for JsonFunc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for JsonFunc

Source§

impl PartialEq for JsonFunc

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for JsonFunc

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.