--
-- Name: period_section_insert(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE or replace FUNCTION period_section_insert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
Declare	sqltext varchar;
BEGIN

	sqltext := (select 'ALTER TABLE FIES.T_MONTH_VALUES ADD ' || New.Alias || ' decimal(20, 6) null;');
	EXECUTE sqltext;

	Return New;

END;
$$;



--
-- Name: period_section_afterinsert; Type: TRIGGER; Schema: public; Owner: sa
--
DO 
$$ 
BEGIN 
IF EXISTS(SELECT * 
                     FROM information_schema.triggers 
                     WHERE event_object_table = lower('T_PERIOD_SECTION') 
                     AND trigger_name = lower('period_section_afterinsert')
                     ) 
                    THEN 
                    DROP TRIGGER period_section_afterinsert ON FIES.T_PERIOD_SECTION;
    END IF ; 

END; 
$$ ;

CREATE TRIGGER period_section_afterinsert AFTER INSERT ON FIES.T_PERIOD_SECTION FOR EACH ROW EXECUTE PROCEDURE period_section_insert();
