Horizon-specific functions, beginning with a date conversion routine
authorBen Ostrowsky <ben@esilibrary.com>
Mon, 21 Nov 2011 15:56:04 +0000 (15:56 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 16 Jul 2012 15:33:04 +0000 (11:33 -0400)
sql/ils_specific/horizon/horizon.sql [new file with mode: 0644]

diff --git a/sql/ils_specific/horizon/horizon.sql b/sql/ils_specific/horizon/horizon.sql
new file mode 100644 (file)
index 0000000..417e923
--- /dev/null
@@ -0,0 +1,21 @@
+CREATE OR REPLACE FUNCTION migration_tools.attempt_hz_date (TEXT,TEXT) RETURNS DATE AS $$
+    DECLARE
+        attempt_value ALIAS FOR $1;
+        fail_value ALIAS FOR $2;
+        output DATE;
+    BEGIN
+        FOR output IN
+            EXECUTE E'SELECT (\'1970-01-01\'::date + \'' || attempt_value || E' days\'::interval)::date AS a;'
+        LOOP
+            RETURN output;
+        END LOOP;
+    EXCEPTION
+        WHEN OTHERS THEN
+            FOR output IN
+                EXECUTE 'SELECT ' || quote_literal(fail_value) || '::date AS a;'
+            LOOP
+                RETURN output;
+            END LOOP;
+    END;
+$$ LANGUAGE PLPGSQL STRICT STABLE;
+