prorm API Reference
    Preparing search index...

    Interface FunctionOptions

    Options for creating a user-defined function (UDF).

    Deliberately shaped to mirror StoredProcedureOptions as closely as possible, since CREATE FUNCTION and CREATE PROCEDURE share almost identical grammar in Postgres-family dialects (CockroachDB, Postgres). The main differences are that a function always has a returnType and may declare a volatility category, which procedures do not have.

    interface FunctionOptions {
        name: string;
        schema?: string;
        params?: StoredProcedureParam[];
        body: string;
        returnType: string;
        language?: string;
        volatility?: "VOLATILE" | "STABLE" | "IMMUTABLE";
        replace?: boolean;
        ifNotExists?: boolean;
        comment?: string;
    }
    Index
    name: string

    Name of the function

    schema?: string

    Schema where the function belongs

    Input parameters

    body: string

    The function body (SQL statements / expression)

    returnType: string

    Return type. Required: unlike procedures, functions always return a value.

    language?: string

    Language (SQL, plpgsql, etc.). Defaults to 'SQL'.

    volatility?: "VOLATILE" | "STABLE" | "IMMUTABLE"

    Volatility/optimization category:

    • VOLATILE (default if omitted): may modify the database and/or return different results on successive calls with the same arguments.
    • STABLE: cannot modify the database, and is guaranteed to return the same results given the same arguments within a single statement.
    • IMMUTABLE: cannot modify the database and always returns the same results given the same arguments. Required for use in computed columns.
    replace?: boolean

    If true, uses CREATE OR REPLACE

    ifNotExists?: boolean

    If true, does not throw if already exists

    comment?: string

    Optional comment