Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFol3-0005Qh-1f for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 22:37:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFol0-00007q-Bx for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 22:37:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFokz-00007h-2d for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 22:37:22 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFoku-0001Oy-JP for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 22:37:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 21C53228C5; Mon, 7 May 2018 18:37:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 07 May 2018 18:37:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=R8JiwEk4fjWRdOIA9b1Oe9wX5IN2R /KYbYIHNBzyl9Y=; b=n4/M1zX0Y4Q0XUoE5SqxbsZJmgh2aiWb3izwAkWEoxan7 CKY6DZZlPGW+eDkx21DjovC6VeNEhhnR2wIaaHmWBdVKxbjlEAGX0FYvJDq2VRNu rL3QDwX12R6SAPE7EVbP9jDPva2TQSYmRNK/EKfbuRmRHQOX88XNhVu8Qa0CYiaZ ML8RYHgN42GB4ApBkUJX0hBXL2WkIa0sKTCdjFyeBZVMeSySsZlGEdRh3SYaWHL4 re9ZgGHNdULcRBBzX1dcxyNTFwLLTq6tVhr7eG5VeQJ7C9gAAssvc3ejotb+9PqI TdRGApNiLcxiONct6ygFFLcjkcid1qjjIAq4Exwdw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=R8JiwE k4fjWRdOIA9b1Oe9wX5IN2R/KYbYIHNBzyl9Y=; b=aX1QlLEXIuyfykGOT7HCEB AH4jdkwQoHJbvkJHrH3RGQ5Dh6UW1TPX93QN3ji/triL6UbYca00CWsIWsbVjAfx j5fSNPSGf7NXJX64kFznLLiGzG3ECQCMeUg8krVw0IM0Aqsi1rW+B6Oe2ghV9RQY DEtLroQHr3tEyzVk17h9TUGygkiK3JE9kMtCb4qJ96BvGi6d2dMrUW7If4SaLw2b QtnJdbq1PjQOacB3VFpwUBejzLE4Gl8Mwbkscrx4cHE+gcwoGcqLxXB3GTbOo7Cx cEbEVOHVQoFmsojUtmz7d+dJ9J76trWo623s+RshQWXGfq/1BJDFnhoL5cxAm0ww == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 5DCE910260; Mon, 7 May 2018 18:37:14 -0400 (EDT) Subject: Re: Run external command as part of an sql statement ? To: David Gauthier , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: Date: Mon, 7 May 2018 15:37:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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