Eli Mesika has uploaded a new change for review.

Change subject: db: add a common function for index creation
......................................................................

db: add a common function for index creation

This patch adds a common function that drop the index if exists and
creates it after that.

This is done in order to prevent scripts failures when the index is not
dropped and an attempt to re-create it is done

Change-Id: I6e6e2577ceac435e25030dfde6ff6c4c3f8a7278
Signed-off-by: Eli Mesika <emes...@redhat.com>
---
M packaging/dbscripts/common_sp.sql
1 file changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/99/34999/1

diff --git a/packaging/dbscripts/common_sp.sql 
b/packaging/dbscripts/common_sp.sql
index 3a1178d..7a07bfb 100644
--- a/packaging/dbscripts/common_sp.sql
+++ b/packaging/dbscripts/common_sp.sql
@@ -421,6 +421,21 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+-- Creates an index on an existing table
+-- Example : Table T with columns a,b and c
+-- fn_db_create_index('T_INDEX', 'T', 'a,b'); ==> Creates an index named 
T_INDEX on table T (a,b)
+create or replace FUNCTION fn_db_create_index(v_index_name varchar(128), 
v_table_name varchar(128), v_column_names text)
+returns void
+AS $procedure$
+DECLARE
+    v_sql TEXT;
+BEGIN
+    v_sql := 'DROP INDEX ' || ' IF EXISTS ' || v_index_name || '; CREATE INDEX 
' || v_index_name || ' ON ' || v_table_name || '(' || v_column_names || ');' ;
+    EXECUTE v_sql;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
 -- Unlocks a specific disk
 create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
 returns void


-- 
To view, visit http://gerrit.ovirt.org/34999
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e6e2577ceac435e25030dfde6ff6c4c3f8a7278
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <emes...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to