Creating A Rule to Increment a class size when a student adds tha t class to their schedule - Mailing list pgsql-sql

From Madel, Kurt
Subject Creating A Rule to Increment a class size when a student adds tha t class to their schedule
Date
Msg-id C6F9B91B745CD4119F1500A0C9DD60C02E3487@exchhq01.usinspect.com
Whole thread Raw
List pgsql-sql
I am trying to create a rule that will increment the class.size in one table
when a student adds that class to their schedule in another table (module).
Basically, there are 3 tables involved:

class
module
student

When a student registers for their classes, the class.id is placed in its
respective module, the student.id is placed in module.student_id which is
combined with module.year to make up the primary key in the module table.

CREATE RULE class_size_increment_cq1 AS 
ON INSERT TO module.c_q1 
DO 
SET class.size to class.size+1 
WHERE class.id=module.c_q1;

This doesn't seem to be working.  Would it be just as fast or faster to use
a transaction:

begin;

insert into module.c_q1.....

update class set class.size to class.size+1 where class.id=module.c_q1;

commit;

TIF,
Kurt


pgsql-sql by date:

Previous
From: "Adam Lang"
Date:
Subject: copy from
Next
From: Jesus Aneiros
Date:
Subject: RE: select an entry with a NULL date field