3 -- Turn off echo and keep things quiet.
5 -- Format the output for nice TAP.
10 -- Revert all changes on failure.
11 \set ON_ERROR_ROLLBACK 1
12 \set ON_ERROR_STOP true
15 -- let's do this thing
20 CREATE OR REPLACE FUNCTION pg_temp.test_phys_char_no_overlaps() RETURNS BOOL AS $$
28 SELECT ptype_key FROM config.marc21_physical_characteristic_type_map
33 SELECT subfield, start_pos, length
34 FROM config.marc21_physical_characteristic_subfield_map
35 WHERE ptype_key = ptype
38 gap := subf.start_pos - LENGTH(str);
40 str := str || REPEAT(' ', gap);
42 -- This is a WARNING instead of an ERROR just so we can
43 -- fail the test nicely. But it really is an error.
44 RAISE WARNING 'subfield % for ptype % backs up!',
48 str := str || REPEAT('|', subf.length);
50 -- RAISE DEBUG '%', str;
58 pg_temp.test_phys_char_no_overlaps(),
60 'Ensure that no set of subfields for a given Physical Characteristics ''type'' (00/a) contains any overlaps.'
63 SELECT * FROM finish();