Thread: triggering on deletes, NEW row or OLD row?

triggering on deletes, NEW row or OLD row?

From
"Peter L. Berghold"
Date:
-----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@Berghold.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

Re: triggering on deletes, NEW row or OLD row?

From
Jaime Casanova
Date:
>
> The question I have is with a trigger on delete are the NEW and OLD
> system variables valid? Which one is valid?
>
>

OLD


--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

Re: triggering on deletes, NEW row or OLD row?

From
Richard Huxton
Date:
Peter L. Berghold wrote:
> The question I have is with a trigger on delete are the NEW and OLD
> system variables valid? Which one is valid?

OLD for deletes. NEW for inserts. Both for updates.

HTH
--
   Richard Huxton
   Archonet Ltd