SELECT approximate_date( $1, '9');
$func$ LANGUAGE SQL STRICT IMMUTABLE;
+CREATE OR REPLACE FUNCTION public.content_or_null( TEXT ) RETURNS TEXT AS $func$
+ SELECT CASE WHEN $1 ~ E'^\\s*$' THEN NULL ELSE $1 END
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
CREATE OR REPLACE FUNCTION public.integer_or_null( TEXT ) RETURNS TEXT AS $func$
SELECT CASE WHEN $1 ~ E'^\\d+$' THEN $1 ELSE NULL END
$func$ LANGUAGE SQL STRICT IMMUTABLE;
WHERE i.func IN ('replace')
AND m.id IN (19);
+INSERT INTO config.record_attr_index_norm_map (attr,norm,pos)
+ SELECT m.name, i.id, 0
+ FROM config.record_attr_definition m,
+ config.index_normalizer i
+ WHERE i.func IN ('content_or_null')
+ AND m.name IN ('titlesort', 'authorsort');
+
+INSERT INTO config.record_attr_index_norm_map (attr,norm,pos)
+ SELECT m.name, i.id, 0
+ FROM config.record_attr_definition m,
+ config.index_normalizer i
+ WHERE i.func IN ('integer_or_null')
+ AND m.name IN ('date1', 'date2', 'pubdate');
+
+INSERT INTO config.record_attr_index_norm_map (attr,norm,pos)
+ SELECT m.name, i.id, 0
+ FROM config.record_attr_definition m,
+ config.index_normalizer i
+ WHERE i.func IN ('approximate_low_date')
+ AND m.name IN ('date1', 'pubdate');
+
+INSERT INTO config.record_attr_index_norm_map (attr,norm,pos)
+ SELECT m.name, i.id, 0
+ FROM config.record_attr_definition m,
+ config.index_normalizer i
+ WHERE i.func IN ('approximate_high_date')
+ AND m.name IN ('date2');
+
-- claims never checked out mark item missing
INSERT INTO
config.org_unit_setting_type ( name, label, description, datatype )
DROP FUNCTION metabib.reingest_metabib_rec_descriptor( bib_id BIGINT );
-COMMIT;
+CREATE OR REPLACE FUNCTION public.approximate_date( TEXT, TEXT ) RETURNS TEXT AS $func$
+ SELECT REGEXP_REPLACE( $1, E'\\D', $2, 'g' );
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.approximate_low_date( TEXT ) RETURNS TEXT AS $func$
+ SELECT approximate_date( $1, '0');
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.approximate_high_date( TEXT ) RETURNS TEXT AS $func$
+ SELECT approximate_date( $1, '9');
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.integer_or_null( TEXT ) RETURNS TEXT AS $func$
+ SELECT CASE WHEN $1 ~ E'^\\d+$' THEN $1 ELSE NULL END
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.content_or_null( TEXT ) RETURNS TEXT AS $func$
+ SELECT CASE WHEN $1 ~ E'^\\s*$' THEN NULL ELSE $1 END
+$func$ LANGUAGE SQL STRICT IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION public.force_to_isbn13( TEXT ) RETURNS TEXT AS $func$
+ use Business::ISBN;
+ use strict;
+ use warnings;
+
+ # Find the first ISBN, force it to ISBN13 and return it
+
+ my $input = shift;
+
+ foreach my $word (split(/\s/, $input)) {
+ my $isbn = Business::ISBN->new($word);
+
+ # First check the checksum; if it is not valid, fix it and add the original
+ # bad-checksum ISBN to the output
+ if ($isbn && $isbn->is_valid_checksum() == Business::ISBN::BAD_CHECKSUM) {
+ $isbn->fix_checksum();
+ }
+
+ # If we now have a valid ISBN, force it to ISBN13 and return it
+ return $isbn->as_isbn13->isbn if ($isbn && $isbn->is_valid());
+ }
+ return undef;
+$func$ LANGUAGE PLPERLU;
+
+COMMENT ON FUNCTION public.force_to_isbn13(TEXT) IS $$
+/*
+ * Copyright (C) 2011 Equinox Software
+ * Mike Rylander <mrylander@gmail.com>
+ *
+ * Inspired by translate_isbn1013
+ *
+ * The force_to_isbn13 function takes an input ISBN and returns the ISBN13
+ * version without hypens and with a repaired checksum if the checksum was bad
+ */
+$$;
+COMMIT;