Index: openacs-4/packages/views/sql/postgresql/views-triggers.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/postgresql/views-triggers.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/views/sql/postgresql/views-triggers.sql	23 Jul 2007 05:25:09 -0000	1.2
+++ openacs-4/packages/views/sql/postgresql/views-triggers.sql	1 Aug 2007 08:59:56 -0000	1.3
@@ -12,51 +12,51 @@
 -- License.  Full text of the license is available from the GNU Project:
 -- http://www.fsf.org/copyleft/gpl.html
 
-create function views_ins_tr () returns opaque as '
+create function views_views_ins_tr () returns opaque as '
 begin
     if not exists (select 1 from view_aggregates where object_id = new.object_id) then 
-        INSERT  INTO view_aggregates (object_id,views,unique_views,last_viewed) 
+        INSERT  INTO view_aggregates (object_id,views_count,unique_views,last_viewed) 
         VALUES (new.object_id,1,1,now());
     else
         UPDATE view_aggregates 
-           SET views = views + 1, unique_views = unique_views + 1, last_viewed = now() 
+           SET views_count = views_count + 1, unique_views = unique_views + 1, last_viewed = now() 
          WHERE object_id = new.object_id;
     end if;
 
     return new;
 end;' language 'plpgsql';
 
-create trigger views_ins_tr 
-after insert on views
+create trigger views_views_ins_tr 
+after insert on views_views
 for each row
-execute procedure views_ins_tr();
+execute procedure views_views_ins_tr();
 
-create function views_upd_tr () returns opaque as '
+create function views_views_upd_tr () returns opaque as '
 begin
     UPDATE view_aggregates 
-       SET views = views + 1, last_viewed = now() 
+       SET views_count = views_count + 1, last_viewed = now() 
      WHERE object_id = new.object_id;
 
     return new;
 end;' language 'plpgsql';
 
-create trigger views_upd_tr
-after update on views
+create trigger views_views_upd_tr
+after update on views_views
 for each row
-execute procedure views_upd_tr();
+execute procedure views_views_upd_tr();
 
 -- XXXJCD: Should there be a delete trigger?
 
-create function views_by_type_ins_tr () returns opaque as '
+create or replace function views_by_type_ins_tr () returns opaque as '
 begin
-    if not exists (select 1 from view_aggregates_by_type where object_id = new.object_id and type = new.type) then 
-        INSERT INTO view_aggregates_by_type (object_id,type,views,unique_views,last_viewed) 
-        VALUES (new.object_id,new.type,1,1,now());
+    if not exists (select 1 from view_aggregates_by_type where object_id = new.object_id and view_type = new.view_type) then 
+        INSERT INTO view_aggregates_by_type (object_id,view_type,views_count,unique_views,last_viewed) 
+        VALUES (new.object_id,new.view_type,1,1,now());
     else
         UPDATE view_aggregates_by_type
-           SET views = views + 1, unique_views = unique_views + 1, last_viewed = now() 
+           SET views_count = views_count + 1, unique_views = unique_views + 1, last_viewed = now() 
          WHERE object_id = new.object_id
-           AND type = new.type;
+           AND view_type = new.view_type;
     end if;
 
     return new;
@@ -67,12 +67,12 @@
 for each row
 execute procedure views_by_type_ins_tr();
 
-create function views_by_type_upd_tr () returns opaque as '
+create or replace function views_by_type_upd_tr () returns opaque as '
 begin
     UPDATE view_aggregates_by_type 
-       SET views = views + 1, last_viewed = now() 
+       SET views_count = views_count + 1, last_viewed = now() 
      WHERE object_id = new.object_id
-       AND type = new.type;
+       AND view_type = new.view_type;
 
     return new;
 end;' language 'plpgsql';
