pub struct CreateFunction<X: Extension = NoExt> {
pub or_replace: bool,
pub definer: Option<Box<Definer>>,
pub if_not_exists: bool,
pub name: ObjectName,
pub params: ThinVec<FunctionParam<X>>,
pub returns: Option<DataType<X>>,
pub options: ThinVec<FunctionOption<X>>,
pub body: Option<Box<FunctionBody<X>>>,
pub meta: Meta,
}Expand description
CREATE [OR REPLACE] FUNCTION <name> ( [<param> [, ...]] ) [RETURNS <type>] [<option> ...].
The routine body has two disjoint grammatical homes on the FunctionBody axis. An
opaque source string is introduced by the order-independent AS option, spelled either
single-quoted (AS 'SELECT 1') or dollar-quoted (AS $$ … $$ / AS $tag$ … $tag$) where
the dialect enables dollar_quoted_strings; the
delimiter and verbatim body text round-trip from the body Literal’s span. A live SQL
body — a SQL-standard RETURN <expr> (PostgreSQL 14+ / standard opt_routine_body) — is
the trailing body slot, which strictly follows the whole option list (proven
against the PG oracle: LANGUAGE sql RETURN 1 accepts, RETURN 1 LANGUAGE sql rejects), so
it is a distinct parse position from AS, not another order-independent option. The two
homes share the FunctionBody type (the axis vocabulary the dollar-body sibling staged)
but not a grammatical slot.
The node is generic over X because a parameter or RETURNS type can be a host-owned
DataType::Other under a custom dialect, and the live
body carries an Expr<X> (stock builtins pin X = NoExt). The M1
surface is the parameter list, an optional RETURNS <type>, the FunctionOption cluster
the corpus exercises (LANGUAGE / AS / null-call behaviour), and the trailing RETURN
body; the fuller volatility, security, parallelism, and SET option matrix — and the
statement-list BEGIN ATOMIC … END body that shares the trailing slot — are deliberate
follow-ups the open option list and the FunctionBody axis extend without a shape change.
Fields§
§or_replace: boolWhether the or replace form was present in the source.
definer: Option<Box<Definer>>The optional MySQL DEFINER = <user> clause; None when omitted (always None
for the PostgreSQL string-body routine, which has no definer prefix). Boxed because a
Definer is comparatively large and the clause is rare, so a definer-less routine
pays only a null pointer (the FunctionParam::default precedent).
if_not_exists: boolWhether the MySQL IF NOT EXISTS guard was written (MySQL 8.0.29+); always false
for PostgreSQL, which spells the intent CREATE OR REPLACE.
name: ObjectNameName referenced by this syntax.
params: ThinVec<FunctionParam<X>>params in source order.
returns: Option<DataType<X>>Optional returns for this syntax.
options: ThinVec<FunctionOption<X>>Options supplied in source order.
body: Option<Box<FunctionBody<X>>>The trailing SQL-standard routine body (opt_routine_body) — a RETURN <expr> live
SQL expression that follows the entire option list. Boxed and optional because it is
usually absent (an AS-string routine leaves it unset, paying one null pointer — the
FunctionParam::default precedent); a FunctionBody::Definition string body never
lands here (it rides the AS option instead).
meta: MetaSource location and node identity.
Trait Implementations§
Source§impl<X: Clone + Extension> Clone for CreateFunction<X>
impl<X: Clone + Extension> Clone for CreateFunction<X>
Source§fn clone(&self) -> CreateFunction<X>
fn clone(&self) -> CreateFunction<X>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de, X> Deserialize<'de> for CreateFunction<X>where
X: Deserialize<'de> + Extension,
impl<'de, X> Deserialize<'de> for CreateFunction<X>where
X: Deserialize<'de> + Extension,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<X: Eq + Extension> Eq for CreateFunction<X>
Source§impl<X: Extension + Render> Render for CreateFunction<X>
impl<X: Extension + Render> Render for CreateFunction<X>
Source§fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
Source§fn operand_binding_power(&self) -> Option<BindingPower>
fn operand_binding_power(&self) -> Option<BindingPower>
None (the default) for a self-delimiting node — an atom, call, or
constructor — that never needs parentheses. Read moreSource§impl<X> Serialize for CreateFunction<X>
impl<X> Serialize for CreateFunction<X>
Source§impl<X: Extension> Spanned for CreateFunction<X>
impl<X: Extension> Spanned for CreateFunction<X>
impl<X: PartialEq + Extension> StructuralPartialEq for CreateFunction<X>
Auto Trait Implementations§
impl<X> Freeze for CreateFunction<X>where
X: Freeze,
impl<X> RefUnwindSafe for CreateFunction<X>where
X: RefUnwindSafe,
impl<X> Send for CreateFunction<X>where
X: Send,
impl<X> Sync for CreateFunction<X>where
X: Sync,
impl<X> Unpin for CreateFunction<X>where
X: Unpin,
impl<X> UnsafeUnpin for CreateFunction<X>where
X: UnsafeUnpin,
impl<X> UnwindSafe for CreateFunction<X>where
X: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynAstExt for T
impl<T> DynAstExt for T
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&dyn Any for downcasting a node back to its concrete type.Source§fn dyn_clone(&self) -> Box<dyn DynAstExt>
fn dyn_clone(&self) -> Box<dyn DynAstExt>
Clone (whose
Self-returning signature cannot go through a vtable).Source§fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
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.