LAQMS
Update pre-QMS landings reported by FMA to the relevant QMS stock
Before a species enters the Quota Management System (QMS), at which point Quota Management Areas (QMAs) are defined, any landings are reported against pseudo-stocks where the landed fishstock is the species code and the general FMA number. This rule updates the landed fishstock for pre-QMS landings of a species to the current QMS fishstock, for landings of species that are currently in the QMS.
-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('LAQMS', 'edw', 'landings', 'Fix', 'Replace pre-QMS pseudo-stock with the post-QMS stock code');
CREATE OR REPLACE FUNCTION LAQMS() RETURNS VOID AS $$
WITH _pre_qms_landings AS
(SELECT l.*
FROM groomed.landings l
JOIN public.species_qms_introduction q USING (species_code)
WHERE l.landing_datetime < q.qms_introduction_date)
INSERT INTO groomed.checks(code, "table", "column", id, orig, new)
SELECT 'LAQMS', 'landings', 'fishstock_code', l.id, l.fishstock_code, s.qma
FROM _pre_qms_landings l
JOIN (SELECT * FROM public.qma_fma_mapping WHERE unique_mapping) s
ON (l.fishstock_code = s.pseudo_stock)
WHERE l.fishstock_code <> s.qma;
UPDATE groomed.landings SET checks = array_append(checks, 'LAQMS'),
fishstock_code = u.new
FROM groomed.checks u
WHERE u.code = 'LAQMS'
AND groomed.landings.id = u.id;
$$ LANGUAGE SQL;
SELECT LAQMS();Effects of grooming