[open-ils-commits] r19491 - trunk/Open-ILS/src/sql/Pg (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Feb 18 15:32:18 EST 2011
Author: miker
Date: 2011-02-18 15:32:13 -0500 (Fri, 18 Feb 2011)
New Revision: 19491
Modified:
trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
Log:
A function for normalizing numeric strings
Modified: trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-02-18 18:46:41 UTC (rev 19490)
+++ trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2011-02-18 20:32:13 UTC (rev 19491)
@@ -605,5 +605,20 @@
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;
More information about the open-ils-commits
mailing list