an attempt_money method for a smaller numeric, given what we use for billings and...
authorJason Etheridge <jason@esilibrary.com>
Wed, 14 Jan 2015 21:53:55 +0000 (21:53 +0000)
committerJason Etheridge <jason@esilibrary.com>
Wed, 14 Jan 2015 21:53:55 +0000 (21:53 +0000)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>

sql/base/base.sql

index 610b741..b828102 100644 (file)
@@ -702,6 +702,27 @@ CREATE OR REPLACE FUNCTION migration_tools.attempt_money (TEXT,TEXT) RETURNS NUM
     END;
 $$ LANGUAGE PLPGSQL STRICT STABLE;
 
+CREATE OR REPLACE FUNCTION migration_tools.attempt_money6 (TEXT,TEXT) RETURNS NUMERIC(6,2) AS $$
+    DECLARE
+        attempt_value ALIAS FOR $1;
+        fail_value ALIAS FOR $2;
+        output NUMERIC(6,2);
+    BEGIN
+        FOR output IN
+            EXECUTE 'SELECT ' || quote_literal(REPLACE(attempt_value,'$','')) || '::NUMERIC(6,2) AS a;'
+        LOOP
+            RETURN output;
+        END LOOP;
+    EXCEPTION
+        WHEN OTHERS THEN
+            FOR output IN
+                EXECUTE 'SELECT ' || quote_literal(fail_value) || '::NUMERIC(6,2) AS a;'
+            LOOP
+                RETURN output;
+            END LOOP;
+    END;
+$$ LANGUAGE PLPGSQL STRICT STABLE;
+
 -- add_codabar_checkdigit
 --   $barcode      source barcode
 --