final class CreateFunction
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

CREATE FUNCTION of a stored function: its parameters, return type, characteristics and body.

The statement is structured as a request: it declares nothing to a context. The facts follow MYSQL-ROUTINE-001. Source: https://dev.mysql.com/doc/refman/8.4/en/create-procedure.html.

Reading a function definitiondoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE FUNCTION twice(a INT) RETURNS BIGINT DETERMINISTIC RETURN a * 2');
    [$create->statement->returns->name(), $create->facts->diagnostics] // => ['BIGINT', []]

Properties§

public list<Characteristic> $characteristics
public ParameterList $parameters
public TypeName $returns
public CollationName|null $collation = null
public Account|null $definer = null
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    public ParameterList $parameters,
    public TypeName $returns,
    Node $body,
    public CollationName|null $collation = null,
    list<Characteristic> $characteristics = [],
    public Account|null $definer = null,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe function name with its optional database
$parametersParameterListThe parameters; none has a direction
$returnsTypeNameThe return type
$bodyNodeThe body: a program statement, an SQL statement, or external code
$collationCollationName|nullThe COLLATE clause of the return type
$characteristicslist<Characteristic>The characteristics in written order
$definerAccount|nullThe DEFINER clause, when written
$ifNotExistsboolWhether IF NOT EXISTS is written (MySQL 8.0.29 and later)

Throws

InvalidConstruction When a parameter has a direction, or the body or a characteristic is of another class
Calls 5
public function deriveStatement(Derivation $derivation): void

Derives the parameters and the body, and checks that the body returns.

Parameters

$derivationDerivation
Calls 3
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 6

Test cases 23§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 3
Other tests reaching this symbol 20

Relations§

Instantiated in 1
Type checks 1
Type declarations 1