<commit_before>CREATE OR REPLACE FUNCTION upgrade_software2() RETURNS VOID AS $$
  DECLARE
    soft          RECORD;
    prop_software RECORD;
    comp          RECORD;
    v_id_software INTEGER;
  BEGIN

    FOR soft IN select  count(distinct id_software) as n_software,
                  display_name
                from proriedade_software
                where display_name is not null
                and display_name <> ''
                group by display_name
                having count(distinct id_software) > 1
                order by n_software desc LOOP

      RAISE NOTICE 'Atualizando nome do software para software = %', soft.display_name;

      -- Considera somente o primeiro software com o nome
      SELECT min(id_software) INTO v_id_software
      FROM proriedade_software
      WHERE display_name = soft.display_name;

      -- Atualiza todas as entradas para o mínimo id_software
      FOR prop_software IN select distinct id_software
                           from proriedade_software
                           WHERE display_name = soft.display_name
                           and id_software <> v_id_software LOOP

        RAISE NOTICE 'Removendo id_software = % e atualizando para id_software = %',prop_software.id_software,v_id_software;

        -- Atualiza propriedade de software
        FOR comp IN select id_class_property,
                      id_computador,
                      id_propriedade_software
                    from proriedade_software
                    WHERE id_software = prop_software.id_software LOOP

          BEGIN
            UPDATE proriedade_software
            SET id_software = v_id_software
            WHERE id_software = prop_software.id_software
            AND id_computador = comp.id_computador
            AND id_class_property = comp.id_class_property;

            EXCEPTION
            WHEN SQLSTATE '23505' THEN
              RAISE NOTICE 'Coleta de software já identificada para o computador no id %. Removendo...', comp.id_propriedade_software;
              DELETE FROM proriedade_software WHERE id_propriedade_software = comp.id_propriedade_software;
          END;



        END LOOP;

        -- Atualiza aquisições de software
        UPDATE aquisicoes_software
        SET id_software = v_id_software
        WHERE id_software = prop_software.id_software;

        -- Agora apaga software
        DELETE FROM software
        WHERE id_software = prop_software.id_software;

      END LOOP;

    END LOOP;

    RETURN;
  END;<commit_msg>Correções para eliminar softwares repetidos<commit_after>CREATE OR REPLACE FUNCTION upgrade_software2() RETURNS VOID AS $$
  DECLARE
    soft          RECORD;
    prop_software RECORD;
    comp          RECORD;
    v_id_software INTEGER;
  BEGIN

    FOR soft IN select  count(distinct id_software) as n_software,
                  display_name
                from proriedade_software
                where display_name is not null
                and display_name <> ''
                group by display_name
                having count(distinct id_software) > 1
                order by n_software desc LOOP

      RAISE NOTICE 'Atualizando nome do software para software = %', soft.display_name;

      -- Considera somente o primeiro software com o nome
      SELECT min(id_software) INTO v_id_software
      FROM proriedade_software
      WHERE display_name = soft.display_name;

      -- Atualiza todas as entradas para o mínimo id_software
      FOR prop_software IN select distinct id_software
                           from proriedade_software
                           WHERE display_name = soft.display_name
                           and id_software <> v_id_software LOOP

        RAISE NOTICE 'Removendo id_software = % e atualizando para id_software = %',prop_software.id_software,v_id_software;

        -- Atualiza propriedade de software
        FOR comp IN select id_class_property,
                      id_computador,
                      id_propriedade_software
                    from proriedade_software
                    WHERE id_software = prop_software.id_software LOOP

          BEGIN
            UPDATE proriedade_software
            SET id_software = v_id_software
            WHERE id_software = prop_software.id_software
            AND id_computador = comp.id_computador
            AND id_class_property = comp.id_class_property;

            EXCEPTION
            WHEN SQLSTATE '23505' THEN
              RAISE NOTICE 'Coleta de software já identificada para o computador no id %. Removendo...', comp.id_propriedade_software;
              DELETE FROM proriedade_software WHERE id_propriedade_software = comp.id_propriedade_software;
          END;

        END LOOP;

        -- Atualiza aquisições de software
        UPDATE aquisicoes_software
        SET id_software = v_id_software
        WHERE id_software = prop_software.id_software;

        -- Agora apaga software
        DELETE FROM software
        WHERE id_software = prop_software.id_software;

      END LOOP;

    END LOOP;

    RETURN;
  END;
{'fraction_non_alphanumeric': 0.03821907013396375, 'fraction_numerical': 0.0027580772261623326, 'mean_word_length': 1.9431884057971014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789316', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1304, 'n_words': 389}