-- -- workflow__create_workflow/6 -- create or replace function workflow__create_workflow( character varying, character varying, character varying, character varying, character varying, character varying ) returns varchar as $$ declare create_workflow__workflow_key alias for $1; create_workflow__pretty_name alias for $2; create_workflow__pretty_plural alias for $3; -- default null create_workflow__description alias for $4; -- default null create_workflow__table_name alias for $5; create_workflow__id_column alias for $6; -- default 'case_id' v_num_rows integer; v_workflow_key varchar; begin select count(*) into v_num_rows from pg_class where relname = lower(create_workflow__table_name); if v_num_rows = 0 then raise EXCEPTION '-20000: The table "%"must be created before calling workflow.create_workflow.', create_workflow__table_name; end if; if substr(create_workflow__workflow_key, length(create_workflow__workflow_key) - 2, 3) != '_wf' then v_workflow_key := create_workflow__workflow_key || '_wf'; else v_workflow_key := create_workflow__workflow_key; end if; PERFORM acs_object_type__create_type ( v_workflow_key, create_workflow__pretty_name, create_workflow__pretty_plural, 'workflow', create_workflow__table_name, create_workflow__id_column, null, 'f', null, null ); insert into wf_workflows (workflow_key, description) values (v_workflow_key, create_workflow__description); return v_workflow_key; end;$$ language plpgsql;