From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | David Gauthier <davegauthierpg(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Run external command as part of an sql statement ? |
Date: | 2018-05-07 22:37:13 |
Message-ID: | fe8905fb-8745-78d5-f129-aa4f4ee7d59f@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)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(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | tango ward | 2018-05-07 23:44:25 | Re: psycopg2.DataError: invalid input syntax for integer: "" |
Previous Message | Tom Lane | 2018-05-07 21:59:06 | Re: How to manipulate tuples in C functions? |