Re: How to use slash commands in a function - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: How to use slash commands in a function
Date
Msg-id 20070216015412.GE4682@alvh.no-ip.org
Whole thread Raw
In response to How to use slash commands in a function  (vanessa <vanessaknell@gmail.com>)
List pgsql-general
vanessa escribió:
>
> Hi guys,
>
> I was wondering how could i (if at all possible) to use say a command like:
> \! touch fred.txt     in a function?
> i.e.
>
> CREATE FUNCTION myfunc() RETURNS TRIGGER AS
> 'BEGIN
>         \! touch fred.txt
>          RETURN NEW;
> END;'
> LANGUAGE 'plpgsql';
>
> At the moment i get:
> ERROR: syntax error at or near "\"
> Does this mean i should encapsulate the line in quotation marks or something
> like that?

No, it means you can't do it at all, because backslash commands are
psql-only, thus you cannot put them in functions (which are
server-executed).  PL/pgSQL functions are trusted, meaning you can't
access the outside world (disk, network, etc) with them.  If you really
need to do that, consider using an untrusted language (C, plperlu, etc).
I think there's even a PL/sh (shell) but I don't think you can use it
for trigger functions.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Where art thou pg_clog?
Next
From: ITAGAKI Takahiro
Date:
Subject: Inequality operators are not deduced.