Re: Run external command as part of an sql statement ? - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Run external command as part of an sql statement ?
Date
Msg-id fe8905fb-8745-78d5-f129-aa4f4ee7d59f@aklaver.com
Whole thread Raw
In response to Run external command as part of an sql statement ?  (David Gauthier <davegauthierpg@gmail.com>)
List pgsql-general
On 05/07/2018 02:35 PM, David Gauthier wrote:
> Hi:
> 
> At the psql prompt, I can do something like...
>     "select  \! id -nu"
> ...to get the uid of whoever's running psql.
> I want to be able to run a shell command like this from within a stored 
> procedure.  Is there a way to do this ?

PL/sh?:

https://github.com/petere/plsh

CREATE OR REPLACE FUNCTION id() RETURNS text AS '
#!/bin/sh
id -nu
' LANGUAGE plsh;

aklaver@tito:~> psql -d test -U postgres

test=# select * from id();
     id
----------
  postgres


It is an untrusted language so you will need to run as a superuser.


> 
> Thanks


-- 
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How to manipulate tuples in C functions?
Next
From: tango ward
Date:
Subject: Re: psycopg2.DataError: invalid input syntax for integer: ""