mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Provide a test for variable existence in psql
"\if :{?variable_name}" will be translated to "\if TRUE" if the variable exists and "\if FALSE" otherwise. Thus it will be possible to execute code conditionally on the existence of the variable, regardless of its value. Fabien Coelho, with some review by Robins Tharakan and some light text editing by me. Discussion: https://postgr.es/m/alpine.DEB.2.20.1708260835520.3627@lancre
This commit is contained in:
@@ -783,6 +783,10 @@ testdb=>
|
||||
The forms <literal>:'<replaceable>variable_name</>'</literal> and
|
||||
<literal>:"<replaceable>variable_name</>"</literal> described there
|
||||
work as well.
|
||||
The <literal>:{?<replaceable>variable_name</>}</> syntax allows
|
||||
testing whether a variable is defined. It is substituted by
|
||||
TRUE or FALSE.
|
||||
Escaping the colon with a backslash protects it from substitution.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -3938,6 +3942,12 @@ testdb=> <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
|
||||
can escape a colon with a backslash to protect it from substitution.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The <literal>:{?<replaceable>name</>}</> special syntax returns TRUE
|
||||
or FALSE depending on whether the variable exists or not, and is thus
|
||||
always substituted, unless the colon is backslash-escaped.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The colon syntax for variables is standard <acronym>SQL</acronym> for
|
||||
embedded query languages, such as <application>ECPG</application>.
|
||||
|
Reference in New Issue
Block a user