Re: cache problem (v2) - Mailing list pgsql-admin

From Andrew Sullivan
Subject Re: cache problem (v2)
Date
Msg-id 20070716170957.GV18049@phlogiston.dyndns.org
Whole thread Raw
In response to cache problem (v2)  (De Leeuw Guy <G.De_Leeuw@eurofer.be>)
Responses Re: cache problem (v2)
List pgsql-admin
I tried to answer the previous version of this mail, but I don't
understand it.  Let me see if my questions trigger something for you,
though.

On Mon, Jul 16, 2007 at 12:32:07PM +0200, De Leeuw Guy wrote:
>
> a table :
> CREATE TABLE test (
>   code                int8 NOT NULL,
>   qte                 float8,
>   CONSTRAINT test_pkey PRIMARY KEY (code)
>  )
> CREATE TRIGGER trig_update_sum BEFORE INSERT OR UPDATE OR DELETE ON
> table_test
>   FOR EACH ROW EXECUTE PROCEDURE gd_trigfunc_before_buildsum();
> EOF
>
> code maybe 1,2,3
> 3 = sum of 1 & 2
>
> the trigger make the sum :

> if event = INSERT code = 3 ==> skip
> if event = INSERT code = 1 or 2
>    if select code 3 exist ? yes = update qte code 3 + qte code x
>                             no  = insert qte to code 3

So if I am reading you correctly, IF code IN (1,2) THEN {do
something}?  What do you do then?  I don't get this part.

> INSERT INTO test VALUES (1, 50);
> INSERT INTO test VALUES (3, 60);
> ok code 3 = 110
>
> psql : delete from test;
> code 1 & 2 deleted
> code 3 = 50

I don't see how this is possible either.  You just deleted from test;
how can you hae anything left in there?

> maybe this is because these commands start a transaction with a cache
> and each time that I request a select for a sum code that are on the
> cache the value returned are not the real new value.

No, but a trigger that executes SQL can cause the trigger to fire
again.  Are you sure that's not happening?

A

--
Andrew Sullivan  | ajs@crankycanuck.ca
Everything that happens in the world happens at some place.
        --Jane Jacobs

pgsql-admin by date:

Previous
From: De Leeuw Guy
Date:
Subject: cache problem (v2)
Next
From: De Leeuw Guy
Date:
Subject: Re: cache problem (v2)