Search Postgresql Archives

Re: Schema in trigger in logical replication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/3/21 2:35 PM, Fontana Daniel C. (Desartec S.R.L.) wrote:
Using postgres 12.5 in DBA schema, this trigger is executed when the table
is updated through a logical replication. Why is it necessary to name the
schema for it to work?

Because the search_path does include the schema?

When I update the table manually, if it Works.

Example.

This trigger function does not work

CREATE FUNCTION dba.ft_pos_sync_eco_tx()
     RETURNS trigger
     LANGUAGE 'plpgsql'
     COST 100
     VOLATILE NOT LEAKPROOF
AS $BODY$
begin
	INSERT INTO pos_sync_eco_rx
     		  (	id_terminales,
            		fecha_y_hora_tx,
            		fecha_y_hora_rx,
			   	dato,
            		usuario,
            		fecha_y_hora_proceso )
	  VALUES (	new.id_terminales,
     			localtimestamp,
            		localtimestamp,
			  	new.dato,
            		new.usuario ,
            		localtimestamp )
	ON CONFLICT (id_terminales)
	DO UPDATE SET (fecha_y_hora_tx,
				   fecha_y_hora_rx,
				   dato,
				   usuario,
				   fecha_y_hora_proceso ) =
				  (new.fecha_y_hora_tx,
				   localtimestamp,
				   new.dato,
				   new.usuario,
				   new.fecha_y_hora_proceso );
				
	return	new;
	
end
$BODY$;

This trigger function, if it works

CREATE FUNCTION dba.ft_pos_sync_eco_tx()
     RETURNS trigger
     LANGUAGE 'plpgsql'
     COST 100
     VOLATILE NOT LEAKPROOF
AS $BODY$
begin
	INSERT INTO dba.pos_sync_eco_rx
     		  (	id_terminales,
            		fecha_y_hora_tx,
            		fecha_y_hora_rx,
			   	dato,
            		usuario,
            		fecha_y_hora_proceso )
	  VALUES (	new.id_terminales,
     			localtimestamp,
            		localtimestamp,
			  	new.dato,
            		new.usuario ,
            		localtimestamp )
	ON CONFLICT (id_terminales)
	DO UPDATE SET (fecha_y_hora_tx,
				   fecha_y_hora_rx,
				   dato,
				   usuario,
				   fecha_y_hora_proceso ) =
				  (new.fecha_y_hora_tx,
				   localtimestamp,
				   new.dato,
				   new.usuario,
				   new.fecha_y_hora_proceso );
				
	return	new;
	
end
$BODY$;




--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux