Annotation: assert.function_exists

CREATE OR REPLACE FUNCTION assert.function_exists(function_name text, OUT message text, OUT result boolean)
RETURNS record

Information: assert.function_exists

Schema assert
Function Name function_exists
Arguments function_name text, OUT message text, OUT result boolean
Owner postgres
Result Type record
Description

Implementation: assert.function_exists

CREATE OR REPLACE FUNCTION assert.function_exists(function_name text, OUT message text, OUT result boolean)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
    IF NOT EXISTS
    (
        SELECT  1
        FROM    pg_catalog.pg_namespace n
        JOIN    pg_catalog.pg_proc p
        ON      pronamespace = n.oid
        WHERE replace(nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ')', ' ' , '')::text=$1
    ) THEN
        message := 'The function % does not exist.', $1;
        PERFORM assert.fail(message);

        result := false;
        RETURN;
    END IF;

    message := 'OK. The function ' || $1 || ' exists.';
    PERFORM assert.ok(message);
    result := true;
    RETURN;
END
$function$