1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +03:00

Add a \getenv command to psql.

\getenv fetches the value of an environment variable into a psql
variable.  This is the inverse of the \setenv command that was added
over ten years ago.  We'd not seen a compelling use-case for \getenv
at the time, but upcoming regression test refactoring provides a
sufficient reason to add it now.

Discussion: https://postgr.es/m/1655733.1639871614@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2021-12-20 13:17:58 -05:00
parent 911588a3f8
commit 33d3eeadb2
4 changed files with 87 additions and 0 deletions

View File

@@ -2237,6 +2237,28 @@ Tue Oct 26 21:40:57 CEST 1999
</varlistentry>
<varlistentry>
<term><literal>\getenv <replaceable class="parameter">psql_var</replaceable> <replaceable class="parameter">env_var</replaceable></literal></term>
<listitem>
<para>
Gets the value of the environment
variable <replaceable class="parameter">env_var</replaceable>
and assigns it to the <application>psql</application>
variable <replaceable class="parameter">psql_var</replaceable>.
If <replaceable class="parameter">env_var</replaceable> is
not defined in the <application>psql</application> process's
environment, <replaceable class="parameter">psql_var</replaceable>
is not changed. Example:
<programlisting>
=&gt; <userinput>\getenv home HOME</userinput>
=&gt; <userinput>\echo :home</userinput>
/home/postgres
</programlisting></para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>\gexec</literal></term>