Question on setting up trigger.

From: Alan Young <alany(at)idiglobal(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Question on setting up trigger.
Date: 2001-01-02 16:38:52
Message-ID: 3A52041C.CBEC614@idiglobal.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have the following table:

CREATE TABLE category (
id int NOT NULL DEFAULT nextval('_base_id_seq'::text) PRIMARY
KEY,
parentid int REFERENCES category ( id )
name text,
);

This allows me to have any number of subcategories without worrying
about how many someone might have.

And I have a function that sets the parentid to the parents parentid
(used when deleting a category) that looks like this:

CREATE FUNCTION "move_catparent" (int4 )
RETURNS int4
AS 'UPDATE category
SET parentid = ( SELECT parentid FROM category WHERE id = $1 )
WHERE parentid = $1;
SELECT 1 AS RESULT'
LANGUAGE 'SQL';

As it stands, I have to do the following when deleting a category:

SELECT move_catparent( <id of category being deleted> );
DELETE FROM category WHERE id=<id of category being deleted>;

I'd like to create a trigger so that I just have to delete the category
and the move_catparent function will be automatically called. I've read
the CREATE TRIGGER documentation, but I'm just not seeing it.

Can anyone give me some pointers? Thanks.

Alan

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Chris 2001-01-02 21:32:17 Re: phppgsqladmin?
Previous Message chris Gnther 2001-01-02 12:07:33 cache lookup error when excuting function