Skip to main content

Syntax

pgschema understands the following CREATE FUNCTION features:
  • Schema-qualified names: Functions can be defined in specific schemas
  • Parameters:
    • IN, OUT, INOUT parameter modes
    • Default parameter values
    • Named parameters with data types
  • Return types:
    • Scalar data types
    • SETOF for set-returning functions
    • TABLE for table-returning functions
    • trigger for trigger functions
  • Languages: Any PostgreSQL procedural language (plpgsql, sql, c, internal, etc.)
  • Security: DEFINER or INVOKER
  • Volatility: IMMUTABLE, STABLE, or VOLATILE
  • STRICT: Returns NULL automatically if any argument is NULL
  • Function body: Any valid function definition with proper dollar-quoting

Canonical Format

When generating migration SQL, pgschema produces functions in the following canonical format:
Key characteristics of the canonical format:
  • Always uses CREATE OR REPLACE FUNCTION for modifications
  • Parameters are formatted with line breaks for readability
  • Explicitly specifies SECURITY mode (INVOKER is default if not specified)
  • Includes volatility when specified
  • Includes STRICT when the function should return NULL on NULL input
  • Uses intelligent dollar-quoting with automatic tag generation to avoid conflicts with function body content
  • For DROP operations: DROP FUNCTION IF EXISTS function_name(argument_types);