killbill-aplcache

ddl: add PostgreSQL-specific DDL Signed-off-by: Pierre-Alexandre

7/14/2015 1:55:04 PM

Details

diff --git a/util/src/main/resources/org/killbill/billing/util/customfield/ddl-postgresql.sql b/util/src/main/resources/org/killbill/billing/util/customfield/ddl-postgresql.sql
new file mode 100644
index 0000000..8d2c5e0
--- /dev/null
+++ b/util/src/main/resources/org/killbill/billing/util/customfield/ddl-postgresql.sql
@@ -0,0 +1,16 @@
+/* We cannot use timestamp in MySQL because of the implicit TimeZone conversions it does behind the scenes */
+CREATE DOMAIN datetime AS timestamp without time zone;
+/* TEXT in MySQL is smaller then MEDIUMTEXT */
+CREATE DOMAIN mediumtext AS text;
+
+CREATE OR REPLACE FUNCTION last_insert_id() RETURNS BIGINT AS $$
+    DECLARE
+        result BIGINT;
+    BEGIN
+        SELECT lastval() INTO result;
+        RETURN result;
+    EXCEPTION WHEN OTHERS THEN
+        SELECT NULL INTO result;
+        RETURN result;
+    END;
+$$ LANGUAGE plpgsql VOLATILE;