FETSE

Set target species to group code for FLA, HPB and OEO species

-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('FETSE', 'edw', 'effort', 'Fix', 'Set target species to group code for FLA, HPB and OEO species');

CREATE OR REPLACE FUNCTION FETSE()
RETURNS VOID AS $$

INSERT INTO groomed.checks(code, "table", "column", id, orig, new)
SELECT 'FETSE', 'effort', 'target_species', id, target_species, 'HPB'
FROM groomed.effort
WHERE target_species IN ('BAS', 'HAP');

UPDATE groomed.effort SET checks = checks || '{FETSE}', target_species = 'HPB'
  WHERE  target_species IN ('BAS', 'HAP');

INSERT INTO groomed.checks(code, "table", "column", id, orig, new)
SELECT 'FETSE', 'effort', 'target_species', id, target_species, 'FLA'
FROM groomed.effort
WHERE target_species IN ('BFL', 'BRI', 'GFL', 'LSO', 'ESO', 'SFL', 'TUR', 'YBF');

UPDATE groomed.effort SET checks = checks || '{FETSE}', target_species = 'FLA'
  WHERE  target_species IN ('BFL', 'BRI', 'GFL', 'LSO', 'ESO', 'SFL', 'TUR', 'YBF');

INSERT INTO groomed.checks(code, "table", "column", id, orig, new)
SELECT 'FETSE', 'effort', 'target_species', id, target_species, 'OEO'
FROM groomed.effort
WHERE target_species IN ('BOE', 'SSO', 'SOR', 'WOE');

UPDATE groomed.effort SET checks = checks || '{FETSE}', target_species = 'OEO'
  WHERE  target_species IN ('BOE', 'SSO', 'SOR', 'WOE');

$$ LANGUAGE SQL;
SELECT FETSE();
Effects of grooming
Figure 1: The number of records affected by the FETSE rule, by year and source.
Figure 2: The proportion of records affected by the FETSE rule, by form type, for all form types where some records are groomed by the FETSE rule.