summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2017-09-21 19:02:23 -0400
committerAndrew Dunstan <andrew@dunslane.net>2017-09-21 19:02:23 -0400
commitd57c7a7c506276597af619bdb8c62fa5b592745a (patch)
tree6cab776216fa74f256164cbbc7859fbe1fb97b02 /doc/src
parent71480501057fee9fa3649b072173ff10e2b842d0 (diff)
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
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml10
1 files changed, 10 insertions, 0 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 60bafa81754..e7a3e17c67b 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -783,6 +783,10 @@ testdb=&gt;
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>
@@ -3939,6 +3943,12 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
</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>.
The colon syntaxes for array slices and type casts are