Here again with other trigger:
the tables structure of the database:
"database_t " (master),
"azienda_vallon e" (SLAVE1),
"azienda_energy " (SLAVE2 )
....
all tables have identical structure.
I want to create a trigger that on updates of table "database_t " I update the fields in the table "azienda_vallon e" and on insert in table "database_t " I insert rows in the table "azienda_vallon e" on one condition: If on updated or inserted row the column intestatario_pr atica = 'AZ. AGR.LA VALLONE' the line goes in table "azienda_vallon e" or if = 'AZ. AGR.LA ENERGY' the line goes "azienda_energy " (this second part not yet implemented in trigger).
Follows my attempt:
that function return no error but on insert or update nothing happens.
thanks to all who help me!!
Sentenza
(I hope I have properly tagged the code)
the tables structure of the database:
"database_t " (master),
"azienda_vallon e" (SLAVE1),
"azienda_energy " (SLAVE2 )
....
all tables have identical structure.
I want to create a trigger that on updates of table "database_t " I update the fields in the table "azienda_vallon e" and on insert in table "database_t " I insert rows in the table "azienda_vallon e" on one condition: If on updated or inserted row the column intestatario_pr atica = 'AZ. AGR.LA VALLONE' the line goes in table "azienda_vallon e" or if = 'AZ. AGR.LA ENERGY' the line goes "azienda_energy " (this second part not yet implemented in trigger).
Follows my attempt:
Code:
CREATE OR REPLACE FUNCTION trig_agg_tab_aziende() RETURNS trigger AS $BODY$ BEGIN IF (TG_OP = 'UPDATE') THEN UPDATE azienda_vallone SET (sigla_comune, foglio, mappale, livello, the_geom, proprieta, denominazione, titolo_disponibilita, titolo_possesso, sigla_provincia, provincia, comune, porzione, sup_catastale, qualita_catastale, vulnerabilita, sup_rilevata, sup_divieto, note_divieto, sup_spandibile, coltura_pac, nome_suolo, num_suolo, fascia_altimetrica, area_omogenea, appezzamento, codice_pua, particella_soppressa, superficie_calcolata, zona_prg, articolo_prg, coltura_pan_09, coltura_pan_10, coltura_pan_11, intestatario_pratica, nome_tabella) = ( NEW.sigla_comune, NEW.foglio, NEW.mappale, NEW.livello, NEW.the_geom, NEW.proprieta, NEW.denominazione, NEW.titolo_disponibilita, NEW.titolo_possesso, NEW.sigla_provincia, NEW.provincia, NEW.comune, NEW.porzione, NEW.sup_catastale, NEW.qualita_catastale, NEW.vulnerabilita, NEW.sup_rilevata, NEW.sup_divieto, NEW.note_divieto, NEW.sup_spandibile, NEW.coltura_pac, NEW.nome_suolo, NEW.num_suolo, NEW.fascia_altimetrica, NEW.area_omogenea, NEW.appezzamento, NEW.codice_pua, NEW.particella_soppressa, NEW.superficie_calcolata, NEW.zona_prg, NEW.articolo_prg, NEW.coltura_pan_09, NEW.coltura_pan_10, NEW.coltura_pan_11, NEW.intestatario_pratica, NEW.nome_tabella) FROM database_t WHERE NEW.intestatario_pratica = 'AZ. AGR.LA VALLONE'; ELSIF (TG_OP = 'INSERT') THEN INSERT INTO azienda_vallone SELECT NEW.sigla_comune, NEW.foglio, NEW.mappale, NEW.livello, NEW.the_geom, NEW.proprieta, NEW.denominazione, NEW.titolo_disponibilita, NEW.titolo_possesso, NEW.sigla_provincia, NEW.provincia, NEW.comune, NEW.porzione, NEW.sup_catastale, NEW.qualita_catastale, NEW.vulnerabilita, NEW.sup_rilevata, NEW.sup_divieto, NEW.note_divieto, NEW.sup_spandibile, NEW.coltura_pac, NEW.nome_suolo, NEW.num_suolo, NEW.fascia_altimetrica, NEW.area_omogenea, NEW.appezzamento, NEW.codice_pua, NEW.particella_soppressa, NEW.superficie_calcolata, NEW.zona_prg, NEW.articolo_prg, NEW.coltura_pan_09, NEW.coltura_pan_10, NEW.coltura_pan_11, NEW.intestatario_pratica, NEW.nome_tabella FROM database_t WHERE NEW.intestatario_pratica = 'AZ. AGR.LA VALLONE'; END IF; RETURN NEW; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100; ALTER FUNCTION trig_agg_tab_aziende() OWNER TO postgres;
thanks to all who help me!!
Sentenza
(I hope I have properly tagged the code)
Comment