Skip to main content

StringFunc

Enum StringFunc 

Source
pub enum StringFunc<X: Extension = NoExt> {
    Substring {
        expr: Box<Expr<X>>,
        start: Option<Box<Expr<X>>>,
        count: Option<Box<Expr<X>>>,
        meta: Meta,
    },
    SubstringSimilar {
        expr: Box<Expr<X>>,
        pattern: Box<Expr<X>>,
        escape: Box<Expr<X>>,
        meta: Meta,
    },
    Position {
        substr: Box<Expr<X>>,
        string: Box<Expr<X>>,
        meta: Meta,
    },
    Overlay {
        target: Box<Expr<X>>,
        replacement: Box<Expr<X>>,
        start: Box<Expr<X>>,
        count: Option<Box<Expr<X>>>,
        meta: Meta,
    },
    Trim {
        side: Option<TrimSide>,
        trim_chars: Option<Box<Expr<X>>>,
        from: bool,
        sources: ThinVec<Expr<X>>,
        meta: Meta,
    },
    CollationFor {
        expr: Box<Expr<X>>,
        meta: Meta,
    },
    ConvertUsing {
        expr: Box<Expr<X>>,
        charset: Ident,
        meta: Meta,
    },
    MatchAgainst {
        columns: ThinVec<Expr<X>>,
        against: Box<Expr<X>>,
        modifier: Option<MatchSearchModifier>,
        meta: Meta,
    },
    CeilTo {
        expr: Box<Expr<X>>,
        field: Ident,
        spelling: CeilSpelling,
        meta: Meta,
    },
    FloorTo {
        expr: Box<Expr<X>>,
        field: Ident,
        meta: Meta,
    },
}
Expand description

A standard-SQL string special form (SQL-92 E021-06/-09/-11 + SQL:1999 T312; PostgreSQL’s func_expr_common_subexpr string productions).

One kind-tagged enum for the keyword-argument string functions: each variant carries exactly its form’s typed fields, and every operand keyword (FROM, FOR, SIMILAR, ESCAPE, PLACING, IN, LEADING/TRAILING/BOTH) is grammar, not data. The comma plain-call spellings (substring(x, 1, 2), trim(x, y), overlay(a, b, c)) are not here — they stay ordinary FunctionCalls, so the plain-call surface every engine also accepts is unaffected by the special forms.

Variants§

§

Substring

SUBSTRING(<expr> FROM <start> [FOR <count>]) and its variants: PostgreSQL admits FOR <count> alone and the reversed FOR <count> FROM <start> spelling (both orders fold onto the same fields and render canonically FROM-first), so at least one of start/count is always present. The string-pattern form SUBSTRING(x FROM 'pat')/… FOR '#' is this same production (the regex reading is runtime semantics, not grammar).

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§start: Option<Box<Expr<X>>>

The FROM <start> operand, None for the FOR-only form.

§count: Option<Box<Expr<X>>>

The FOR <count> operand, None for the FROM-only form.

§meta: Meta

Source location and node identity.

§

SubstringSimilar

PostgreSQL’s SUBSTRING(<expr> SIMILAR <pattern> ESCAPE <escape>) regex form (SQL:1999 <regular expression substring function>). All three operands are mandatory (SUBSTRING(x SIMILAR p) without ESCAPE rejects, engine-verified).

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§pattern: Box<Expr<X>>

The SQL-regex pattern.

§escape: Box<Expr<X>>

The escape-character expression.

§meta: Meta

Source location and node identity.

§

Position

POSITION(<substr> IN <string>) (SQL-92 E021-11). The operands are the restricted b_expr in PostgreSQL/DuckDB (POSITION(1 IN 2 OR 3) rejects) and MySQL’s asymmetric bit_expr IN expr under StringFuncForms::position_asymmetric_operands. There is no plain-call spelling: every keyword-form engine parse-rejects position(a, b).

Fields

§substr: Box<Expr<X>>

The substring to search for.

§string: Box<Expr<X>>

The string searched within.

§meta: Meta

Source location and node identity.

§

Overlay

OVERLAY(<target> PLACING <replacement> FROM <start> [FOR <count>]) (SQL:1999 T312). FROM <start> is mandatory — OVERLAY(x PLACING y) and the FOR-without-FROM form parse-reject on every keyword-form engine.

Fields

§target: Box<Expr<X>>

Object targeted by this syntax.

§replacement: Box<Expr<X>>

The replacement string spliced in.

§start: Box<Expr<X>>

The 1-based start position.

§count: Option<Box<Expr<X>>>

Optional count for this syntax.

§meta: Meta

Source location and node identity.

§

Trim

TRIM([{BOTH | LEADING | TRAILING}] [<chars>] FROM <sources>…) (SQL-92 E021-09) plus PostgreSQL’s loose trim_list tails under StringFuncForms::trim_list_syntax: a bare FROM <list>, a side without FROM (TRIM(TRAILING ' foo ')), and a multi-expression list (TRIM('a' FROM 'b', 'c')). At least one of side/from is present — a bare TRIM(x)/TRIM(x, y) is an ordinary call, never this node.

Fields

§side: Option<TrimSide>

The written BOTH/LEADING/TRAILING side, None when omitted.

§trim_chars: Option<Box<Expr<X>>>

The trim-character expression written before FROM; None for the bare-FROM and side-without-FROM forms.

§from: bool

Whether FROM was written (distinguishes TRIM(TRAILING ' foo ') from TRIM(TRAILING FROM ' foo ') — both are valid PostgreSQL with different meanings, so the bit is load-bearing for round-trips).

§sources: ThinVec<Expr<X>>

The source expression list after FROM (or the bare list when a side is written without FROM). PostgreSQL’s trim_list is an expr_list, so more than one source parses there; the restricted dialects hold this to exactly one at parse.

§meta: Meta

Source location and node identity.

§

CollationFor

PostgreSQL’s COLLATION FOR (<expr>) — the common-subexpr that reports the collation name derived for its operand. PostgreSQL gives it a dedicated COLLATION FOR '(' a_expr ')' production that lowers to a pg_catalog.pg_collation_for(<expr>) call, but the surface keyword form is kept here (not folded to a FunctionCall) so it round-trips as written. The parentheses and single a_expr operand are mandatory — COLLATION FOR 'x', COLLATION FOR (), and a two-argument list all parse-reject (engine-verified).

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§meta: Meta

Source location and node identity.

§

ConvertUsing

MySQL’s CONVERT(<expr> USING <charset>) transcoding form — reinterprets its string operand in another character set (the grammar’s CONVERT '(' expr USING charset_name ')'). Distinct from the comma-form cast CastSyntax::Convert: this changes the charset, not the type, so it is a string special form rather than a cast. The operand is a full a_expr (CONVERT(1+2 USING utf8mb4) parses, engine-verified); charset is a MySQL charset_name — an ident_or_text (a bare or backtick identifier, or a quoted string, round-tripping by the Ident’s quote style) or the BINARY transcoding name (CONVERT(x USING binary)), which reaches here as a bare Ident. Recognized only under CallSyntax::convert_function; MySQL-only.

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§charset: Ident

The target character set name.

§meta: Meta

Source location and node identity.

§

MatchAgainst

MySQL’s full-text search MATCH (<col>, …) AGAINST (<expr> [<modifier>]) (simple_expr: MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')'). The columns are a comma list of column references (bare or 1–3-part dotted Expr::Columns — an arbitrary expression, literal, function call, or empty list all parse-reject, engine-verified); against is a MySQL bit_expr (below the comparison level, so a trailing IN/WITH opens the modifier rather than an IN predicate). The optional MatchSearchModifier is exactly one of the four documented combinations; None is the default (no modifier words) and round-trips as written rather than as an explicit IN NATURAL LANGUAGE MODE. Recognized only under StringFuncForms::match_against; MySQL-only, and distinct from SQLite’s infix <expr> MATCH <expr> operator. Semantic constraints (a full-text index must cover the columns, the operand must be constant) are a server binding concern, not grammar.

Fields

§columns: ThinVec<Expr<X>>

Columns in source order.

§against: Box<Expr<X>>

The full-text search expression.

§modifier: Option<MatchSearchModifier>

Optional modifier for this syntax.

§meta: Meta

Source location and node identity.

§

CeilTo

CEIL(<expr> TO <field>) / CEILING(<expr> TO <field>) — a rounding-field keyword form distinct from the ordinary CEIL(<expr>) call and the comma-form scale spelling CEIL(<expr>, <scale>) (which stays an ordinary FunctionCall: no probed oracle grammar admits the TO tail, engine-verified against pg_query, DuckDB, and mysql:8.4). The field (DAY, HOUR, …) is stored as written and validated, if at all, by the consuming engine at analysis time, not parse. Recognized only under StringFuncForms::ceil_to_field.

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§field: Ident

The rounding field (DAY, HOUR, …).

§spelling: CeilSpelling

Exact source spelling retained for faithful rendering.

§meta: Meta

Source location and node identity.

§

FloorTo

FLOOR(<expr> TO <field>) — a rounding-field keyword form distinct from the ordinary FLOOR(<expr>) call and the comma-form scale spelling FLOOR(<expr>, <scale>) (which stays an ordinary FunctionCall: no probed oracle grammar admits the TO tail, engine-verified against pg_query, DuckDB, and mysql:8.4). Unlike StringFunc::CeilTo, FLOOR has no FLOORING synonym, so there is no spelling field to track. The field (DAY, HOUR, …) is stored as written and validated, if at all, by the consuming engine at analysis time, not parse. Recognized only under StringFuncForms::floor_to_field.

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§field: Ident

The rounding field (DAY, HOUR, …).

§meta: Meta

Source location and node identity.

Trait Implementations§

Source§

impl<X: Clone + Extension> Clone for StringFunc<X>

Source§

fn clone(&self) -> StringFunc<X>

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<X: Debug + Extension> Debug for StringFunc<X>

Source§

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

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

impl<'de, X> Deserialize<'de> for StringFunc<X>
where X: Deserialize<'de> + Extension,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<X: Eq + Extension> Eq for StringFunc<X>

Source§

impl<X: Hash + Extension> Hash for StringFunc<X>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<X: PartialEq + Extension> PartialEq for StringFunc<X>

Source§

fn eq(&self, other: &StringFunc<X>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<X: Extension + Render> Render for StringFunc<X>

Source§

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

Return the render for this value.
Source§

fn operand_binding_power(&self) -> Option<BindingPower>

The binding power this node contributes when it appears as an operand, or None (the default) for a self-delimiting node — an atom, call, or constructor — that never needs parentheses. Read more
Source§

impl<X> Serialize for StringFunc<X>
where X: Serialize + Extension,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<X: Extension> Spanned for StringFunc<X>

Source§

fn span(&self) -> Span

Return the span for this value.
Source§

impl<X: PartialEq + Extension> StructuralPartialEq for StringFunc<X>

Auto Trait Implementations§

§

impl<X> Freeze for StringFunc<X>

§

impl<X> RefUnwindSafe for StringFunc<X>
where X: RefUnwindSafe,

§

impl<X> Send for StringFunc<X>
where X: Send,

§

impl<X> Sync for StringFunc<X>
where X: Sync,

§

impl<X> Unpin for StringFunc<X>
where X: Unpin,

§

impl<X> UnsafeUnpin for StringFunc<X>

§

impl<X> UnwindSafe for StringFunc<X>
where X: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynAstExt for T
where T: Extension + Render + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Erase to &dyn Any for downcasting a node back to its concrete type.
Source§

fn dyn_clone(&self) -> Box<dyn DynAstExt>

Clone into a fresh box — the object-safe stand-in for Clone (whose Self-returning signature cannot go through a vtable).
Source§

fn dyn_eq(&self, other: &dyn DynAstExt) -> bool

Structural equality against another erased node — the object-safe stand-in for PartialEq (whose &Self argument cannot go through a vtable). Equal iff other holds the same concrete type and that type deems the values equal; differently-typed nodes are never equal.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feed this node’s hash into an erased hasher — the object-safe stand-in for Hash::hash (whose generic H: Hasher cannot go through a vtable).
Source§

impl<T> Extension for T
where T: Clone + Debug + Eq + Hash + Spanned,

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> RenderExt for T
where T: Render,

Source§

fn displayed<'a>(&'a self, ctx: &'a RenderCtx<'a>) -> Displayed<'a, T>

Pair this node with an explicit canonical RenderCtx so format!, to_string, and {} render it. This is the canonical path: the ctx’s resolver and source must match the node’s parse.
Source§

fn debug_sql<'a>(&'a self, resolver: &'a dyn Resolver) -> DebugSql<'a, Self>
where Self: Sized,

Render this node for debugging against an explicitly-supplied resolver (the debug-SQL mitigation), returning a Display adapter. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.