Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d29-5.10.0d29.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/Attic/upgrade-5.10.0d29-5.10.0d29.sql,v
diff -u -r1.1.2.1 -r1.1.2.2
--- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d29-5.10.0d29.sql	11 May 2020 18:51:26 -0000	1.1.2.1
+++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d29-5.10.0d29.sql	11 May 2020 19:09:53 -0000	1.1.2.2
@@ -29,3 +29,68 @@
    END IF;
 END;
 $$ LANGUAGE plpgsql;
+
+--
+-- procedure util__table_column_exists/1
+--
+CREATE OR REPLACE FUNCTION util__table_column_exists(
+   p_table  text,
+   p_column text
+) RETURNS boolean AS $$
+DECLARE
+ v_schema    varchar;
+ v_tablename varchar;
+BEGIN
+    IF (position('.' in p_table) = 0) THEN
+	--
+	-- table without a schema name
+	--
+	return exists (
+	    select 1 from information_schema.columns c
+	    where table_name  = lower(p_table)
+	    and column_name = lower(p_column));
+    ELSE
+	--
+	-- table with schema name
+	--
+	SELECT split_part(p_table, '.', 1) into v_schema;
+	SELECT split_part(p_table, '.', 2) into v_tablename;
+	return exists (
+	    select 1 from information_schema.columns
+	    where table_name  = lower(v_tablename)
+	    and column_name = lower(p_column)
+	    and table_schema = v_schema);
+    END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+
+--
+-- procedure util__view_exists/1
+--
+CREATE OR REPLACE FUNCTION util__view_exists(
+   name text
+) RETURNS boolean AS $$
+DECLARE
+ v_schema    varchar;
+ v_tablename varchar;
+BEGIN
+    IF (position('.' in name) = 0) THEN
+	--
+	-- view without a schema name
+	--
+	return exists (
+	   select 1 from pg_views where viewname = name);
+    ELSE
+	--
+	-- table with schema name
+	--
+	SELECT split_part(name, '.', 1) into v_schema;
+	SELECT split_part(name, '.', 2) into v_tablename;
+	return exists (
+	    select 1 from information_schema.views
+	    where table_name  = lower(v_tablename)
+	    and table_schema = v_schema);
+    END IF;
+END;
+$$ LANGUAGE plpgsql;
