CREATE EXTENSION hstore;
CREATE TABLE skm_employee_skillset
(
employee_id integer PRIMARY KEY,
created_date DATE DEFAULT current_date,
last_update DATE DEFAULT current_date,
created_by integer NOT NULL,
updated_by integer NOT NULL,
employee_skill_values hstore
);
CREATE OR REPLACE FUNCTION skm_skills_manager__employee_skillset_insert(
v_employee_id integer,
v_user integer,
v_skill_type_prefix char(2),
v_skill_type_id integer,
v_skill_level_confirmed boolean,
v_skill_level_confirmed_by integer )
RETURNS boolean AS $$
BEGIN
Insert into skm_employee_skillset
(employee_id ,
created_date,
last_update ,
created_by,
updated_by,
employee_skill_values)
VALUES
(v_employee_id,
DEFAULT,
DEFAULT,
v_user,
v_user,
hstore(ARRAY['skill_type_prefix','skill_type_id','skill_level_confirmed','skill_level_confirmed_by']
, ARRAY[v_skill_type_prefix::TEXT,v_skill_type_id::TEXT,v_skill_level_confirmed::TEXT,v_skill_level_confirmed_by::TEXT]) );
return TRUE;
EXCEPTION
when others then return FALSE;
end;
$$ language plpgsql;
select skm_skills_manager__employee_skillset_insert(4,2,'aa',4,true,2);
select * from skm_employee_skillset;
employee_id |created_date |last_update |created_by |updated_by |employee_skill_values |
------------|-------------|------------|-----------|-----------|------------------------------------------------------------------------------------------------------------------|
4 |2018-10-09 |2018-10-09 |2 |2 |"skill_type_id"=>"4", "skill_type_prefix"=>"aa", "skill_level_confirmed"=>"true", "skill_level_confirmed_by"=>"2" |