CREATE FUNCTION, PROCEDURE, TRIGGER, EXTENSION

Every procedural CREATE in v0.1.0 — exact syntax, what parses, what executes, what is stub.

Version
Latest
v0.1.0 · latest 2 min read
On this page
  1. CREATE FUNCTION — parses
  2. CREATE PROCEDURE — parses
  3. CREATE TRIGGER — parses
  4. CREATE EXTENSION — parses
  5. Related
Note

Status labels in this page: Parses means the statement is accepted by crates/sql/src/parser/create.rs:parse_other_create into CreateStatement::{Function, Procedure, Trigger, Extension} but has no execution in v0.1.0. Only CREATE TYPE / DOMAIN / SEQUENCE in this family have runtime effects. Do not build on stubs.

CREATE FUNCTION — parses#

textsource
CREATE FUNCTION name ( [ [argname] datatype [, ...] ] )
RETURNS rettype
LANGUAGE lang
AS $$ body $$ | AS 'body'

Source: CreateStatement::Function { name, args: Vec<FunctionArg{name, data_type}>, returns, language, body }.

sqlsource
CREATE FUNCTION add_two(a INT, b INT) RETURNS INT LANGUAGE sql AS $$ SELECT a + b $$;

Behavior: accepted, stored nowhere, callable nowhere. Calling SELECT add_two(1,2) → unknown-function error. DROP FUNCTION name[(types)] [CASCADE|RESTRICT] parses and removes the stub entry shape only.

What to use instead: implement logic in SQL expressions, views, or application code. See Functions.

CREATE PROCEDURE — parses#

sqlsource
CREATE PROCEDURE clean_old_orders() LANGUAGE sql AS
  $$ DELETE FROM orders WHERE placed_at < now() - INTERVAL '1 year' $$;

CreateStatement::Procedure { name } only — args/body discarded shapes. No CALL execution in v0.1.0.

CREATE TRIGGER — parses#

sqlsource
CREATE TRIGGER audit_insert AFTER INSERT ON orders FOR EACH ROW EXECUTE FUNCTION audit_fn();

CreateStatement::Trigger { name } only. No firing, no audit_fn resolution, no OLD/NEW support.

CREATE EXTENSION — parses#

sqlsource
CREATE EXTENSION pgcrypto;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CreateStatement::Extension { name } only. No loading, no new functions/types. If you need gen_random_uuid()-style helpers, they do not exist in v0.1.0 — generate UUIDs client-side.

Was this page helpful?