triggering on deletes, NEW row or OLD row?

From: "Peter L(dot) Berghold" <Peter(at)berghold(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: triggering on deletes, NEW row or OLD row?
Date: 2005-12-13 17:13:33
Message-ID: 439F013D.10103@Berghold.Net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi folks,

I hope this question isn't a stupid one, but I'm fairly much a newbie to
SQL in general and Postgres in particular.

I have a table (abbreviated for clarity sake) that contains:

create table change_record (
change_record_id integer not null
default nextval('change_record_id_seq')
primary key,
--- Some other fields
associated_with_project boolean not null default 'false'
);

and a second table such that:

create change_record_map (
change_record_map_id integer not null
default nextval('change_record_map_id_seq')
primary key,
change_record_id integer not null
references change_record(change_record_id)
on delete cascade,
project_id integer not null
references projects(project_id)
on delete cascade
);

What I want to put into my schema is two triggers. One for when a row
is added to the change_record_map it forces the column in the
change_record table "associated_with_project" to be set to true
appropriately. That part I have down OK.

The other trigger I want to put in place is when a delete happens to a
record in the table change_record_map I check to make sure that the
associated change record is not associated with another project (could
happen) and force the associated_with_project column in the
change_record table to false ONLY if there are no other associated
projects.

The question I have is with a trigger on delete are the NEW and OLD
system variables valid? Which one is valid?

- --
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Peter L. Berghold Peter(at)Berghold(dot)Net
"Those who fail to learn from history are condemned to repeat it."
AIM: redcowdawg Yahoo IM: blue_cowdawg ICQ: 11455958
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDnwE9UM9/01RIhaARAtSAAJ9JeRDrUQr0LI8965+Mgs7DmS/wOACeIWTU
SBhMrFAAlEvE2qdgFOk81tk=
=WrRq
-----END PGP SIGNATURE-----

Attachment Content-Type Size
Peter.vcf text/x-vcard 192 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martin Pitt 2005-12-13 17:26:29 Re: Bug#342369: PostgreSQL 8.1.0 RHEL / Debian incompatible
Previous Message Richard Huxton 2005-12-13 17:06:04 Re: Toolkit for creating editable grid