Skip to end of banner
Go to start of banner

MODSOURMAN-632 Create a script to delete duplicate mapping rules for each record type

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Script to delete duplicated mapping rules by record type:

Delete duplicated mapping rules
DELETE FROM
	diku_mod_source_record_manager.mapping_rules a
	USING diku_mod_source_record_manager.mapping_rules b
	WHERE a.id < b.id AND a.record_type = b.record_type
RETURNING a.id, a.record_type;

Alternative approach with function:

Delete duplicated from mapping rules
CREATE OR REPLACE FUNCTION delete_mapping_rules_duplicates(university text) RETURNS TABLE(id uuid, record_type text) AS $$
DECLARE
    module_name text := university || '_mod_source_record_manager';
BEGIN
RETURN QUERY
    EXECUTE format('DELETE FROM
                         %s.mapping_rules a
                         USING %s.mapping_rules b
                    WHERE a.id < b.id AND a.record_type = b.record_type
                    RETURNING a.id, a.record_type::text;', module_name, module_name);
    END;
$$ LANGUAGE 'plpgsql';
  • No labels