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

	sqltext := (select 'ALTER TABLE FIES.T_MO_PEOPLE ADD ' || New.Alias || ' int null;');
	EXECUTE sqltext;

	Return New;

END;
$$;



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

END; 
$$ ;

CREATE TRIGGER age_group_afterinsert AFTER INSERT ON FIES.T_AGE_GROUP FOR EACH ROW EXECUTE PROCEDURE age_group_insert();
