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

CREATE [OR REPLACE] FUNCTION or PROCEDURE: defines a routine.

Mirrors PostgreSQL's CreateFunctionStmt. The result is a type, a table of columns, or, for a function with output parameters or a procedure, not written. The body is either an option (AS 'definition') or an SQL-standard body (RETURN expression or BEGIN ATOMIC ... END) whose statements are analyzed with the parameters visible. A definition written as a string is unanalysed text in the routine's language (PG-ROUTINE-SOURCE-001): the server parses it only when the routine runs. Defining a routine declares no relation. Source: https://www.postgresql.org/docs/17/sql-createfunction.html, https://www.postgresql.org/docs/17/sql-createprocedure.html.

Reading the parameters of a functiondoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE FUNCTION add(a int4, b int4) RETURNS int4 RETURN a + b');
    [$operation->statement->name->last()->value, count($operation->statement->parameters->parameters)] // => ['add', 2]

Properties§

public list<RoutineOption> $options
public DottedName $name
public RoutineParameters $parameters
public TypeName|ResultTable|null $returns
public ReturnStatement|AtomicBody|null $body = null
public bool $procedure = false
public bool $replace = false

Methods§

public function __construct(
    public DottedName $name,
    public RoutineParameters $parameters,
    public TypeName|ResultTable|null $returns,
    list<RoutineOption> $options = [],
    public ReturnStatement|AtomicBody|null $body = null,
    public bool $procedure = false,
    public bool $replace = false,
)

Parameters

$nameDottedNameThe routine name
$parametersRoutineParametersThe parameters
$returnsTypeName|ResultTable|nullThe written result; a procedure has none
$optionslist<RoutineOption>The options in written order
$bodyReturnStatement|AtomicBody|nullThe SQL-standard body, if written
$procedureboolWhether a procedure is defined
$replaceboolWhether OR REPLACE is written
Calls 3
public function deriveStatement(Derivation $derivation): void

Derives the parameters, the result, the options and the body.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 10§

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

Dedicated tests 4
Other tests reaching this symbol 6

Relations§

Instantiated in 4
Type declarations 6