1
I’m having a hard time create a function in the Postgres execute a command shell linux, with one detail: it is a function in a Trigger after insert and I need to use some columns from NEW.
In Mysql, using the plugin "Mysql UDF" was very simple, the trigger was like this:
BEGIN
DECLARE result int(10);
SET result = sys_exec
(
'/usr/bin/php /var/www/html/.../regras.php
NEW.uniqueid NEW.linkedid NEW.eventtype'
);
END
Now on the PostgreSQL, I installed the language PL/sh, which enables the execution of any script sh, then I tried the following function:
CREATE FUNCTION tarifador_func2() RETURNS TRIGGER
LANGUAGE plsh
AS $$
#!/bin/sh
/usr/bin/php /var/www/html/...regras.php
NEW.uniqueid NEW.linkedid NEW.eventtype
$$;
It gets to run the file php, the problem is that this language does not recognize the nomenclature NEW, there the values in args that I receive are exactly the writings that I pass in the parameter.
Does anyone know any way to use the NEW in PL/sh?
Another solution would be to manually pass the three values I need per argument in creating the Trigger and in the function I would use $1, $2 and $3.
That would be possible somehow?
Question has been answered here: Running system command with argument in a Postgresql Function - Stackoverflow
– Guilherme B