ANTON KADACH

Generation

code to explanationWed, 18 Jan 2023

create or replace function add_in_group_versions( current_id_gp int8, link_code text)--current_id_gp int8, RETURNS void LANGUAGE plpgsql AS $function$ declare ver_id int8; begin select v.id from change_request."version" v join gp_project gp on gp.version_id= v.id where v.version_is_actual and gp.code in ($2) into ver_id; insert into change_request.group_versions (group_id, version_id) select distinct gv2.group_id , ver_id from change_request.group_versions gv join change_request.group_versions gv2 on gv2.group_id = gv.group_id join change_request."groups" g on g.id = gv2.group_id join gp_project gp on gp.version_id =g.version_id where gp.id = $1 on conflict do nothing; END; $function$;

This function is intended to add a new group in the group_versions table. The function takes two arguments: the id of the group whose links are to be added and the code of the links to be added. The function returns nothing. The function select the id of the version in which the link is stored and stores it into the variable ver_id. If a link is in more than one version, the version with the highest id is selected. If the link is not loaded in the database, the function returns nothing. Then the function inserts the id of the group and the id of the version in which the link is stored (ver_id) into the group_versions table. The group_versions table stores the links (identified by their id in the table versions) of the groups (identified by their id in the table groups). If a group is in more than one version, the function stores the different versions.

Questions about programming?Chat with your personal AI assistant