Re: Triggers in postgres

From: "Henshall, Stuart - WCP" <SHenshall(at)westcountrypublications(dot)co(dot)uk>
To: 'Rob' <rob(at)obsidian(dot)co(dot)za>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Triggers in postgres
Date: 2002-03-19 11:20:50
Message-ID: E2870D8CE1CCD311BAF50008C71EDE8E01F74833@MAIL_EXCHANGE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Foreign Keys should be able to do what you want.
Example, not at all tested:
CREATE TABLE product ( barcode serial,
PRIMARY KEY (barcode));
CREATE TABLE catalog ( pk serial,
fk int4,
PRIMARY KEY (pk),
FOREIGN KEY (fk) REFERENCES product
(barcode) ON DELETE CASCADE );

When an entery in the product table is deleted, any enteries in catalog with
fk=barcode should be deleted as well.
For more info see CREATE TABLE in the DOCs
(eg http://www.postgresql.org/idocs/index.php?sql-createtable.html )
Also you should be able to add foriegn keys using ALTER TABLE
Hope this helps,
- Stuart

> -----Original Message-----
> From: Rob [mailto:rob(at)obsidian(dot)co(dot)za]
> Sent: 19 March 2002 16:40
> To: pgsql-novice(at)postgresql(dot)org
> Subject: [NOVICE] Triggers in postgres
>
>
> Hi,
>
> I have a product table with a column barcode. After a
> product has been
> deleted, I want to create a trigger to delete references to
> that product
> in other tables. I've got the following trigger
>
> CREATE TRIGGER
> AFTER DELETE
> ON TABLE product
> FOR EACH ROW
>
> Now, what I would ideally like to do is issue a simple sql
> delete command,
> but I think I actually have to define a function (is this
> true?). Say I
> do, then the rest of my trigger would look like
>
> EXECUTE PROCEDURE someProc();
>
> Now I need to pass somProc the barcode of the product I've
> just deleted.
> How do I do this?
>
> Thanks
>
> Rob
>
> --
> He who dies with the most toys ...
>
> ... still dies
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to
> majordomo(at)postgresql(dot)org)
>

Browse pgsql-novice by date

  From Date Subject
Next Message Stein Eldar Johnsen 2002-03-19 15:28:23 undefined reference to `PgConnection type_info function'
Previous Message Oliver Elphick 2002-03-19 11:12:49 Re: Triggers in postgres