CREATE OR REPLACE FUNCTION public.store_bv() RETURNS TRIGGER AS $store_bv$ update ed_explore."bv" set END IF; In the BEFORE trigger you cannot use an explicit “UPDATE …” statement. You want to do: NEW.c_vmax_actuel = ((NEW.d_capacite_barrages_new) / (30*86400)); To update the value of the in-context record directly within the trigger itself. If the table is at all large this is better anyway since you are not continually updating EVERY SINGLE RECORD regardless of whether it was recently changed. The IF statement, checking for INSERT or UPDATE, is redundant since you should only attach this function to triggers that only fire on insert or update. David J. From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Red Light Hi Dave, when i use before trigger , nothing happen; i mean no cumputation is done (and when i start tu duplicate the same data just by mistake ...) i got the same error.
You set the trigger to fire off whenever ed_expore.bv is inserted or updated. Then the trigger updates ed_explore.bv, which fires the update trigger again, etc... . Infinite loop. No? Maybe you just want to use a before trigger to set that value before the insert, then you wouldn't need the recursive after trigger? From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Red Light Hi guys, i got the following problematic : i got a table called bv that have some 'entry data' and i have another column that need to be calculated and put back in the table: here is my table: CREATE TABLE public.bv i created a trigger that do the necessary computation: CREATE OR REPLACE FUNCTION public.store_bv() RETURNS TRIGGER AS $store_bv$ the declaration of my trigger : CREATE TRIGGER store_bv_trigger and now i start to insert my data: insert into public.bv (id_bv,d_capacite_barrages_new) values (1,7324591);commit; then the trigger got executed and goes in an infinite loop,here is the error that i got : ERREUR: dépassement de limite (en profondeur) de la pile And thanks for you help |