state := REGEXP_REPLACE( city_state_zip, E'^(.*),(.*)$', E'\\2');
city := REGEXP_REPLACE( city_state_zip, E'^(.*),(.*)$', E'\\1');
ELSE
- IF city_state_zip ~ E'\\s+[A-Z][A-Z]\\s*' THEN
- state := REGEXP_REPLACE( city_state_zip, E'^.*,?\\s+([A-Z][A-Z])\\s*.*$', E'\\1' );
- city := REGEXP_REPLACE( city_state_zip, E'^(.*?),?\\s+[A-Z][A-Z](\\s*.*)$', E'\\1\\2' );
+ IF city_state_zip ~ E'\\s+[A-Z][A-Z]\\s*$' THEN
+ state := REGEXP_REPLACE( city_state_zip, E'^.*,?\\s+([A-Z][A-Z])\\s*$', E'\\1' );
+ city := REGEXP_REPLACE( city_state_zip, E'^(.*?),?\\s+[A-Z][A-Z](\\s*)$', E'\\1\\2' );
ELSE
IF city_state_zip ~ E'^\\S+$' THEN
city := city_state_zip;
return "$prefix$new_barcode$suffix";
$$ LANGUAGE PLPERLU STABLE;
-CREATE OR REPLACE FUNCTION migration_tools.attempt_cast (TEXT,TEXT,TEXT) RETURNS RECORD AS $$
+-- remove previous version of this function
+DROP FUNCTION IF EXISTS migration_tools.attempt_cast(TEXT, TEXT, TEXT);
+
+CREATE OR REPLACE FUNCTION migration_tools.attempt_cast (TEXT, TEXT) RETURNS TEXT AS $$
DECLARE
attempt_value ALIAS FOR $1;
datatype ALIAS FOR $2;
- fail_value ALIAS FOR $3;
- output RECORD;
BEGIN
- FOR output IN
- EXECUTE 'SELECT ' || quote_literal(attempt_value) || '::' || datatype || ' AS a;'
- LOOP
- RETURN output;
- END LOOP;
+ EXECUTE 'SELECT ' || quote_literal(attempt_value) || '::' || datatype || ' AS a;';
+ RETURN attempt_value;
EXCEPTION
- WHEN OTHERS THEN
- FOR output IN
- EXECUTE 'SELECT ' || quote_literal(fail_value) || '::' || datatype || ' AS a;'
- LOOP
- RETURN output;
- END LOOP;
+ WHEN OTHERS THEN RETURN NULL;
END;
$$ LANGUAGE PLPGSQL STRICT STABLE;
my $xml = shift;
-eval { my $r = MARC::Record->new_from_xml( $xml ); };
+eval {
+ my $r = MARC::Record->new_from_xml( $xml );
+ my $output_xml = $r->as_xml_record();
+};
if ($@) {
return 0;
} else {
The fourth argument is the character to set the indicator value to.
All occurences of the specified field will be changed.
The function returns the revised MARCXML string.$$;
+
+CREATE OR REPLACE FUNCTION migration_tools.create_staff_user(
+ username TEXT,
+ password TEXT,
+ org TEXT,
+ perm_group TEXT,
+ first_name TEXT DEFAULT '',
+ last_name TEXT DEFAULT ''
+) RETURNS VOID AS $func$
+BEGIN
+ RAISE NOTICE '%', org ;
+ INSERT INTO actor.usr (usrname, passwd, ident_type, first_given_name, family_name, home_ou, profile)
+ SELECT username, password, 1, first_name, last_name, aou.id, pgt.id
+ FROM actor.org_unit aou, permission.grp_tree pgt
+ WHERE aou.shortname = org
+ AND pgt.name = perm_group;
+END
+$func$
+LANGUAGE PLPGSQL;