Skip to content

Add support for Postgres Functions #829

@scribahti

Description

@scribahti

Enhancement

Add support to generate CREATE OR REPLACE FUNCTION sql scripts using dbml markdown.

Syntax

Function increment {
    schema public
    returns integer
    args [len_from: integer, len_from: integer]
    body `
        DECLARE
            film_count INTEGER;
        BEGIN
            SELECT COUNT(*) 
            INTO film_count
            FROM film
            WHERE length BETWEEN len_from AND len_to;
            RETURN film_count;
        END;
    `
    language plpgsql
    behavior volatile
    security invoker
}

schema defaults to public. Can be specified inline with the function name such as Function public.increment { ... }
returns accepts any valid return type (see list below).
args accepts a list of arguments with declared types. Any return type is valid, excluding void, record, and trigger.
body accepts an expression or a multi-line expression.
language defaults to plpgsql. Can be sql, c, or internal.
behavior defaults to volatile. Can be immutable or stable.
security defaults to invoker. Can be definer.

Return types:

  • void
  • record
  • trigger
  • integer
  • bool
  • bytea
  • date
  • double_precision
  • float4
  • float8
  • int2
  • int4
  • int8
  • json
  • jsonb
  • numeric
  • text
  • time
  • timestamp
  • timestamptz
  • timetz
  • uuid
  • varchar
  • vector

Gaps

Does not implement configuration parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions