Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

570
Vistas
execute external program with trigger in postgres 9.4

I am searching for a way to execute a system command after update or insert with a trigger. I hope that postgres can do this. Is it possible?

CREATE TRIGGER check_update
AFTER UPDATE ON allowed_member_type
FOR EACH ROW
EXECUTE PROCEDURE check_account_update();

thanks in advance

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Disclamer: I work with Andreas Fritsch on the same project.

We have solved this problem in the following way.

There is an "Language"-extension PL/sh Procedural Language Handler for PostgreSQL coded by Peter Eisentraut which does exactly what we need.

You define a shell-script like this:

CREATE or REPLACE FUNCTION test(text) RETURNS text AS '
#!/bin/bash
echo Test: $1 is working
' LANGUAGE plsh;

This is an example of a trigger-function with some usefull environment-variables for triggers:

CREATE or REPLACE FUNCTION TriggerTest() RETURNS trigger AS $$
#!/bin/bash
#mkdir /has/triggertest/$PLSH_TG_NAME
cd /has/triggertest
touch PLSH_TG_NAME-$PLSH_TG_NAME
touch PLSH_TG_WHEN-$PLSH_TG_WHEN
touch PLSH_TG_LEVEL-$PLSH_TG_LEVEL
touch PLSH_TG_OP-$PLSH_TG_OP
touch PLSH_TG_TABLE_NAME-$PLSH_TG_TABLE_NAME
touch PLSH_TG_TABLE_SCHEMA-$PLSH_TG_TABLE_SCHEMA
touch new-$new.x
#touch "arg-0-'$0'"
touch "arg-1-'$1'"
touch "arg-2-'$2'"
touch "arg-3-'$3'"
touch "arg-4-'$4'"

for arg do
    touch "Arg is '$arg'"
done

exit 0
$$ LANGUAGE plsh;

You create a before-insert-trigger with the following SQL-Statement

CREATE TRIGGER tbefore BEFORE INSERT OR UPDATE OR DELETE ON ttest2
    FOR EACH ROW EXECUTE PROCEDURE TriggerTest(new);

I hope this helps anybody else who is looking for a similar solution for his problem.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda