Re: executing os commands from a function

Поиск
Список
Период
Сортировка
От Igor Neyman
Тема Re: executing os commands from a function
Дата
Msg-id MWHPR07MB287708970BF2580A0F8868E4DAC10@MWHPR07MB2877.namprd07.prod.outlook.com
обсуждение исходный текст
Ответ на executing os commands from a function  ("Armand Pirvu (home)" <armand.pirvu@gmail.com>)
Список pgsql-general
-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Armand Pirvu (home)
Sent: Thursday, September 29, 2016 5:42 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] executing os commands from a function


All

I know this may sound like heresy since it involves executing an OS command from a function , but here goes

After an insert in a table, I want to touch a file

I.e

After insert into table test values (100) I want in a dir to have file 100

I used plsh extension but I had to use two functions and a trigger, see code below

CREATE or REPLACE FUNCTION func2 (var1 text) RETURNS text AS '
#!/bin/bash
 touch /home/postgres/$1;
' LANGUAGE plsh;
commit;

CREATE FUNCTION func1() RETURNS trigger AS '
BEGIN
perform   func2(NEW.col1);
RETURN NEW;
END;
' LANGUAGE plpgsql;

CREATE TRIGGER trigf1 BEFORE INSERT on test
    FOR EACH ROW EXECUTE PROCEDURE func1();

testdb=# insert into test3 values (777); INSERT 0 1 testdb=# select * from test3;
 col1
------
  777

[postgres@edb1 ~]$ ls -ltr
-rw------- 1 postgres postgres     0 Sep 29 16:30 777


It works but can I be simpler ? Any other alternatives ? In Ingres for example I can use dbevent and an esqlc app which
listens 


Thank you

Armand
__________________________________________________________________________________________________________

Similar mechanism exists in Postgresql.
Read about LISTEN/NOTIFY in the docs.

Regards,
Igor Neyman



В списке pgsql-general по дате отправления:

Предыдущее
От: Jerome Wagner
Дата:
Сообщение: Re: Multi tenancy : schema vs databases
Следующее
От: Vick Khera
Дата:
Сообщение: Re: Multi tenancy : schema vs databases