3 SELECT evergreen.upgrade_deps_block_check('0767', :eg_version);
5 CREATE OR REPLACE FUNCTION evergreen.could_be_serial_holding_code(TEXT) RETURNS BOOL AS $$
10 my $holding_code = (new JSON::XS)->decode(shift);
11 new MARC::Field('999', @$holding_code);
14 # verify that subfield labels are exactly one character long
15 foreach (keys %{ { @$holding_code } }) {
16 return 0 if length($_) != 1;
21 COMMENT ON FUNCTION evergreen.could_be_serial_holding_code(TEXT) IS
22 'Return true if parameter is valid JSON representing an array that at minimu
23 m doesn''t make MARC::Field balk and only has subfield labels exactly one character long. Otherwise false.';
26 -- This UPDATE throws away data, but only bad data that makes things break
28 UPDATE serial.issuance
29 SET holding_code = NULL
30 WHERE NOT could_be_serial_holding_code(holding_code);
32 ALTER TABLE serial.issuance
33 DROP CONSTRAINT IF EXISTS issuance_holding_code_check;
35 ALTER TABLE serial.issuance
36 ADD CHECK (holding_code IS NULL OR could_be_serial_holding_code(holding_code));