pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Madel, Kurt <KMadel@USInspect.com>
To: pgsql-sql@postgresql.org
Subject: Use a rule or a transaction
Date: Tue, 15 Aug 2000 13:57:17 -0400
Message-ID: <C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com> (raw)

Hello,

I am creating a web based (using php) class registration database with three
tables directly effected by the registration process:

1) class
2) student
3) module

The module table has a field for every module (or class period) for every
student that registers for a given year.  When a student registers for a
given class, the class.id for that class is placed in the respective module
field.

However, if class.size is equal to class.maxsize, then I don't want to allow
that class.id to be inserted into the module table.  If the class.size is
ok, then the class.id should be added to the given module field, module.a_q1
for example AND the class.size needs to be incremented by one (further, the
class.size needs to be decremented if a student drops a class).

My question is, would it be better (faster) to use rules or to use a
transaction.

Also, if I use a transaction, it would look something like this:

>begin work;
>insert into module (a_q1) values (1);
>update class set class.size=class.size+1 where class.id=1 and
class.size<class.maxsize;
>commit work;

>begin work;
>insert into module (a_q2) values (3);
>update class set class.size=class.size+1 where class.id=1 and
class.size<class.maxsize;
>commit work;

...and so on
If I did it this way, I would have to do this for 4 quarters by 6 modules
(24 times).
I feel like I have to do it one by one, because a student should only not
get registered for classes that are full.  I don't want to lump all 24
modules into one transaction and then have the student start the
registration process entirely over because one class was full. 

Is there a faster way to do this with rules or a better way to do it
otherwise.

TIF,
Kurt



view thread (8+ messages)  latest in thread

Message-ID: <C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com>
Permalink:  ../C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com/
Also on:    postgresql.org/message-id/C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: KMadel@USInspect.com
  Subject: Re: Use a rule or a transaction
  In-Reply-To: <C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com>
  References: <C6F9B91B745CD4119F1500A0C9DD60C02E348E@exchhq01.usinspect.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox