From: miker Date: Fri, 18 Feb 2011 20:32:13 +0000 (+0000) Subject: A function for normalizing numeric strings X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0bbca3f632956a623a3dc3b42280422262e1fce4;p=evergreen%2Fpines.git A function for normalizing numeric strings git-svn-id: svn://svn.open-ils.org/ILS/trunk@19491 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql index ec2dbf268c..a68300ff7f 100644 --- a/Open-ILS/src/sql/Pg/002.functions.config.sql +++ b/Open-ILS/src/sql/Pg/002.functions.config.sql @@ -605,5 +605,20 @@ CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$ SELECT CAST(REGEXP_REPLACE(UPPER($1), $$\\$$, $$\\\\$$, 'g') AS BYTEA); $_$ LANGUAGE SQL IMMUTABLE; +CREATE OR REPLACE FUNCTION lpad_number_substrings( TEXT, TEXT, INT ) RETURNS TEXT AS $$ + my $string = shift; + my $pad = shift; + my $len = shift; + my $find = $len - 1; + + while ($string =~ /(?:^|\D)(\d{1,$find})(?:$|\D)/) { + my $padded = $1; + $padded = $pad x ($len - length($padded)) . $padded + $string =~ s/$1/$padded/sg; + } + + return $string; +$$ LANUGAGE PLPERLU; + COMMIT;