From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David Gauthier <davegauthierpg@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Run external command as part of an sql statement ?
Date: Mon, 7 May 2018 15:37:13 -0700
Message-ID: <fe8905fb-8745-78d5-f129-aa4f4ee7d59f@aklaver.com> (raw)
In-Reply-To: <CAMBRECD0cW4mvg_ZfRX=qW8iJanCVjQU+j=Yx5J7jbn4uBSZ2Q@mail.gmail.com>
References: <CAMBRECD0cW4mvg_ZfRX=qW8iJanCVjQU+j=Yx5J7jbn4uBSZ2Q@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, davegauthierpg@gmail.com
Subject: Re: Run external command as part of an sql statement ?
In-Reply-To: <fe8905fb-8745-78d5-f129-aa4f4ee7d59f@aklaver.com>
References: <CAMBRECD0cW4mvg_ZfRX=qW8iJanCVjQU+j=Yx5J7jbn4uBSZ2Q@mail.gmail.com> <fe8905fb-8745-78d5-f129-aa4f4ee7d59f@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox