-- File: generate_comments_copy_function.eex.sql
-- Location: musebms/database/all/ms_syst_priv/functions/generate_comments_copy_function.eex.sql
-- Project: Muse Systems Business Management System
--
-- Copyright © Lima Buttgereit Holdings LLC d/b/a Muse Systems
-- This file may include content copyrighted and licensed from third parties.
--
-- See the LICENSE file in the project root for license terms and conditions.
-- See the NOTICE file in the project root for copyright ownership information.
--
-- muse.information@musesystems.com :: https://muse.systems
DECLARE
var_source_comments text;
var_resolved_supplemental text;
var_function_comments text;
BEGIN
var_source_comments :=
( SELECT
pgd.description
FROM
pg_catalog.pg_proc pgp
JOIN pg_catalog.pg_namespace pgn
ON pgn.oid = pgp.pronamespace
JOIN pg_catalog.pg_description pgd
ON pgd.objoid = pgp.oid
WHERE
pgd.classoid = 'pg_proc'::regclass
AND pgd.objsubid = 0
AND pgn.nspname = p_source_schema
AND pgp.proname = p_source_name);
var_resolved_supplemental :=
E'**Supplemental Notes**\n\n' || p_supplemental;
var_function_comments :=
regexp_replace(
coalesce(var_source_comments || E'\n', '') ||
coalesce(var_resolved_supplemental || E'\n', ''),
'[\n\r\f\u000B\u0085\u2028\u2029]{3,}',
E'\n\n' );
EXECUTE format( 'COMMENT ON FUNCTION %1$I.%2$I IS %3$L;',
p_target_schema,
p_target_name,
var_function_comments);
END;