Re: Mutating table (urgent) - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Mutating table (urgent)
Date
Msg-id 20030221103303.L59965-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Mutating table (urgent)  ("Cristian Custodio" <crstian@terra.com.br>)
List pgsql-general
On Fri, 21 Feb 2003, Cristian Custodio wrote:

> 3) Creating trigger on principal table
>    CREATE OR REPLACE FUNCTION TR_AIPAI() RETURNS OPAQUE AS '
>    BEGIN
>     INSERT INTO FILHO (CODPAI, NOMFIL) VALUES (NEW.CODPAI, ''FILHO DO PAI''||NEW.CODPAI);
>     RETURN NULL;
>    END;
>    ' language 'plpgsql';
>
>    CREATE TRIGGER AIPAI AFTER  INSERT ON PAI FOR EACH ROW EXECUTE PROCEDURE TR_AIPAI();
>
> If we taking a insert on principal table it will insert on child table,
> until here, thats all right...
>
> 4) Create a trigger on child table that make a select on principal table
>    CREATE OR REPLACE FUNCTION TR_SELECT_PAI() RETURNS OPAQUE AS'
>    DECLARE I INTEGER;
>    BEGIN
>     SELECT COUNT(*) INTO I FROM PAI;
>     RETURN NULL;
>    END;
>    'language 'plpgsql';
>
>    CREATE TRIGGER BIFILHO BEFORE INSERT ON FILHO FOR EACH ROW EXECUTE PROCEDURE TR_SELECT_PAI();

By returning NULL in a BEFORE trigger you're saying to drop the request on
the floor.


pgsql-general by date:

Previous
From: Doug McNaught
Date:
Subject: Re: transactions
Next
From: Stephan Szabo
Date:
Subject: Re: A problem with sequences...