Re: How to execute external script from a TRIGGER or FUNCTION ?

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Denis BUCHER <dbucherml(at)hsolutions(dot)ch>
Subject: Re: How to execute external script from a TRIGGER or FUNCTION ?
Date: 2009-08-02 01:03:18
Message-ID: 4A74E5D6.8080508@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Denis BUCHER wrote:
> Hello,
>
> Denis BUCHER a écrit :
>> I need to execute an external script from Postgresql, it could be in
>> perl, in bash/shell, in whatever...
>>
>> Any help would be appreciated ! I just need a very simple example if
>> possible...
>>
>> I already searched on the web but found nothing...
>
> After hours of search, I searched just some more and I think I found the
> solution, hope it can be useful to someone else :
>
> CREATE LANGUAGE plperlu;
>
> CREATE FUNCTION test_perl_external (integer) RETURNS boolean AS $$
> $filename = '/tmp/somefile';
> if (-e $filename) { return true; }
> return false;
> $$ LANGUAGE plperlu;
>
> SELECT test_perl_external(1);
>
> Denis
>
>

You want to run a script? The above would test to see if it exists, but not run it.

Use qx/cmd args/ or system('cmd args') to run it. (In perl anyway, I dunno if plperl supports it)

-Andy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2009-08-02 01:19:07 Re: questions on (parallel) COPY and when to REINDEX
Previous Message Janet Jacobsen 2009-08-01 21:24:41 questions on (parallel) COPY and when to REINDEX