Search Postgresql Archives

triggering on deletes, NEW row or OLD row?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----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@xxxxxxxxxxxx
"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-----
begin:vcard
fn:Peter  L. Berghold
n:Berghold;Peter 
org:IBM;GSD
email;internet:peter@xxxxxxxxxxxx
title:Unix Specialist
x-mozilla-html:FALSE
url:http://www.berghold.net
version:2.1
end:vcard


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux