From 2ea3ae1008020589b43a51663c45556a08547212 Mon Sep 17 00:00:00 2001
From: Florian Dold <florian@dold.me>
Date: Fri, 2 Jun 2023 11:46:48 +0200
Subject: make CREATE TYPE usage idempotent

PostgresSQL doesn't have a CREATE TYPE OR REPLACE, so we have to work
around this with exception handling.
---
 src/exchangedb/exchange_do_reserves_in_insert.sql | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

(limited to 'src/exchangedb/exchange_do_reserves_in_insert.sql')

diff --git a/src/exchangedb/exchange_do_reserves_in_insert.sql b/src/exchangedb/exchange_do_reserves_in_insert.sql
index 20d1c55a2..cf57d8e81 100644
--- a/src/exchangedb/exchange_do_reserves_in_insert.sql
+++ b/src/exchangedb/exchange_do_reserves_in_insert.sql
@@ -970,15 +970,16 @@ END $$;
 
 
 
-
-
-
-
-
-CREATE TYPE exchange_do_array_reserve_insert_return_type
-  AS
-  (transaction_duplicate BOOLEAN
-  ,ruuid INT8);
+DO $$
+BEGIN
+  CREATE TYPE exchange_do_array_reserve_insert_return_type
+    AS
+    (transaction_duplicate BOOLEAN
+    ,ruuid INT8);
+EXCEPTION
+  WHEN duplicate_object THEN null;
+END
+$$;
 
 CREATE OR REPLACE FUNCTION exchange_do_array_reserves_insert(
   IN in_gc_date INT8,
-- 
cgit v1.2.3

