Index: openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.9.1d1-5.9.1d2.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.9.1d1-5.9.1d2.sql,v
diff -u -r1.1.2.1 -r1.1.2.2
--- openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.9.1d1-5.9.1d2.sql	25 Nov 2016 11:22:52 -0000	1.1.2.1
+++ openacs-4/packages/acs-lang/sql/postgresql/upgrade/upgrade-5.9.1d1-5.9.1d2.sql	26 Nov 2016 07:42:03 -0000	1.1.2.2
@@ -1,3 +1,21 @@
 
--- index reference on users table
-create index ad_locale_user_prefs_user_id_idx on ad_locale_user_prefs(user_id);
+
+DO $$
+DECLARE
+        v_found boolean;
+BEGIN
+        --
+        -- Was the index already created?
+        --
+        SELECT exists(
+           SELECT relname from pg_class
+           WHERE relname ='ad_locale_user_prefs_user_id_idx'
+        ) into v_found;
+        
+        if v_found IS FALSE then
+	   --
+	   -- create index for user preferences for locales
+	   --
+           create index ad_locale_user_prefs_user_id_idx on ad_locale_user_prefs(user_id);
+        end if;
+END $$;
