From 7de1ce6f3bac767eb0e44db20465d069d4d46168 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 19 May 2017 13:30:07 +0000
Subject: [PATCH] Task #10811: Cannot use "IF NOT EXISTS" in "CREATE TABLE AS"
 in postgres <9.4

---
 .../ResourceAssignmentDatabase/radb/sql/README                | 4 ++++
 .../radb/sql/add_functions_and_triggers.sql                   | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/README b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/README
index bdb88dbe568..9901f24b17d 100644
--- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/README
+++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/README
@@ -28,8 +28,12 @@ To create a fresh and empty RADB, follow the following steps.
     ssh scu199
 * Obtain/adjust the relevant credentials. As lofarsys:
     cat ~/.lofar/dbcredentials/radb.ini
+* Stop any services interacting with the radb:
+    supervisorctl -p 123 stop ra_services:
 * If you want a NEW database, create one (see radb.ini for the relevant parameters):
     (see create_database.sql)
 * Reinitialise the database (see radb.ini for the relevant parameters):
     psql -h $DBHOST $DATABASE -U $DBUSER -f create_and_populate_database.sql -W
 * Ignore all NOTICES.
+* Stop any services interacting with the radb:
+    supervisorctl -p 123 start RA_Services:
diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
index 948dde1a867..4ad59a10a6e 100644
--- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
+++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
@@ -561,7 +561,7 @@ BEGIN
     -- for performance reasons we repeat the common code here instead of wrapping the common code in a function
 
     --get all overlapping_claims, whether they cause a conflict or not.
-    CREATE TEMPORARY TABLE IF NOT EXISTS overlapping_claims
+    CREATE TEMPORARY TABLE overlapping_claims
     ON COMMIT DROP
     AS SELECT * FROM resource_allocation.resource_claim rc
     WHERE rc.resource_id = claim.resource_id
@@ -626,7 +626,7 @@ BEGIN
     --RAISE NOTICE 'get_conflicting_overlapping_claims(%)...', claim;
 
     --get all overlapping_claims, whether they cause a conflict or not.
-    CREATE TEMPORARY TABLE IF NOT EXISTS overlapping_claims
+    CREATE TEMPORARY TABLE overlapping_claims
     ON COMMIT DROP
     AS SELECT * FROM resource_allocation.resource_claim rc
     WHERE rc.resource_id = claim.resource_id
-- 
GitLab