Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

577
Views
ejecutar programa externo con disparador en postgres 9.4

Estoy buscando una forma de ejecutar un comando del sistema después de actualizar o insertar con un disparador. Espero que postgres pueda hacer esto. ¿Es posible?

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

gracias de antemano

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Descargo de responsabilidad: trabajo con Andreas Fritsch en el mismo proyecto.

Hemos resuelto este problema de la siguiente manera.

Hay un controlador de lenguaje procedimental PL/sh con extensión de "Idioma" para PostgreSQL codificado por Peter Eisentraut que hace exactamente lo que necesitamos.

Usted define un script de shell como este:

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

Este es un ejemplo de una función de activación con algunas variables de entorno útiles para los activadores:

 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;

Usted crea un disparador de inserción anterior con la siguiente instrucción SQL

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

Espero que esto ayude a cualquier otra persona que esté buscando una solución similar para su problema.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!