LASCI

State code invalid

Change invalid state codes to NULL. Valid state codes are maintained in the public.state_codes table from published Regulations and Circulars.

-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('LASCI', 'edw', 'landings', 'Flag', 'Landings to invalid state code');

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

INSERT INTO groomed.checks(code, "table", "column", id, orig, new)
SELECT 'LASCI', 'landings', 'state_code', id, state_code, NULL
FROM   groomed.landings
WHERE  state_code NOT IN (SELECT code FROM public.state_codes);

UPDATE groomed.landings
SET    checks=array_append(checks,'LASCI'),
       state_code = NULL
FROM   groomed.checks u
WHERE  u.code = 'LASCI'
AND    groomed.landings.id = u.id
AND    groomed.landings.state_code = u.orig;

$$ LANGUAGE SQL;

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