Skip to content
User-Defined Functions

SQL scalar functions and PL/pgSQL stored procedures

Define reusable functions in SQL or PL/pgSQL. Call them from any query. Functions are stored in the catalog and visible across sessions.

Scalar functions defined as SQL expressions
PL/pgSQL stored procedures with control flow
Stored in the catalog, governed by the same RBAC
SQL UDF CREATE FUNCTION analytics.tax_amount (price DECIMAL, rate DECIMAL) RETURNS DECIMAL AS price * rate SELECT analytics.tax_amount (unit_price, 0.0825) FROM orders Catalog schema-scoped, RBAC-controlled CREATE PROCEDURE analytics.refresh_summary LANGUAGE plpgsql AS $$ BEGIN ... END $$;

SQL scalar UDFs

A function body is any SQL expression; the result is the return type you declare

Simple expressions

Define a function as a single SQL expression. The optimizer can inline it at query planning time.

CREATE FUNCTION price_with_tax(p DECIMAL, r DECIMAL)
RETURNS DECIMAL AS p * (1 + r);

Type coercion

Arguments are automatically coerced to the declared parameter types following standard SQL rules.

Schema scoping

Functions belong to a schema. GRANT and REVOKE control which roles can call them.

Overloading

Multiple functions with the same name but different parameter types resolve by the best-matching signature.

PL/pgSQL stored procedures

Procedural control flow over Delta tables using the PostgreSQL procedural language

Control flow

IF/ELSIF/ELSE, FOR loops, WHILE, CASE, and RAISE. Full procedural logic in the same file as your SQL.

DO blocks

Anonymous PL/pgSQL blocks with DO $$ BEGIN ... END $$; for one-off procedural execution.

Stored procedures

CREATE PROCEDURE ... LANGUAGE plpgsql stores the body in the catalog. Call with CALL schema.proc();

Parameter support

IN, OUT, and INOUT parameters. Procedures can return result sets or write state back through OUT parameters.

Extend the engine with your own logic

SQL expressions and PL/pgSQL procedures, stored in the catalog, callable from any query.