CreateFunctionBody in sqlparser::ast - Rust

Enum CreateFunctionBody 

Source

pub enum CreateFunctionBody {
    AsBeforeOptions {
        body: Expr,
        link_symbol: Option<Expr>,
    },
    AsAfterOptions(Expr),
    AsBeginEnd(BeginEndStatements),
    Return(Expr),
    AsReturnExpr(Expr),
    AsReturnSelect(Select),
}
Expand description

Represent the expression body of a CREATE FUNCTION statement as well as where within the statement, the body shows up.

§

A function body expression using the ‘AS’ keyword and shows up before any OPTIONS clause.

Example:

CREATE FUNCTION myfunc(x FLOAT64, y FLOAT64) RETURNS FLOAT64
AS (x * y)
OPTIONS(description="desc");

Fields

§body: Expr

The primary expression.

Link symbol if the primary expression contains the name of shared library file.

Example:

CREATE FUNCTION cas_in(input cstring) RETURNS cas
AS 'MODULE_PATHNAME', 'cas_in_wrapper'
§

A function body expression using the ‘AS’ keyword and shows up after any OPTIONS clause.

Example:

CREATE FUNCTION myfunc(x FLOAT64, y FLOAT64) RETURNS FLOAT64
OPTIONS(description="desc")
AS (x * y);
§

Function body with statements before the RETURN keyword.

Example:

CREATE FUNCTION my_scalar_udf(a INT, b INT)
RETURNS INT
AS
BEGIN
    DECLARE c INT;
    SET c = a + b;
    RETURN c;
END
§

Function body expression using the ‘RETURN’ keyword.

Example:

CREATE FUNCTION myfunc(a INTEGER, IN b INTEGER = 1) RETURNS INTEGER
LANGUAGE SQL
RETURN a + b;
§

Function body expression using the ‘AS RETURN’ keywords

Example:

CREATE FUNCTION myfunc(a INT, b INT)
RETURNS TABLE
AS RETURN (SELECT a + b AS sum);
§

Function body expression using the ‘AS RETURN’ keywords, with an un-parenthesized SELECT query

Example:

CREATE FUNCTION myfunc(a INT, b INT)
RETURNS TABLE
AS RETURN SELECT a + b AS sum;

§
§
§
§
§
§