@@ -823,6 +823,14 @@ testdb=>
823
823
continue beyond the end of the line.
824
824
</para>
825
825
826
+ <para>
827
+ Many of the meta-commands act on the <firstterm>current query buffer</>.
828
+ This is simply a buffer holding whatever SQL command text has been typed
829
+ but not yet sent to the server for execution. This will include previous
830
+ input lines as well as any text appearing before the meta-command on the
831
+ same line.
832
+ </para>
833
+
826
834
<para>
827
835
The following meta-commands are defined:
828
836
@@ -1713,22 +1721,28 @@ testdb=>
1713
1721
<listitem>
1714
1722
<para>
1715
1723
If <replaceable class="parameter">filename</replaceable> is
1716
- specified, the file is edited; after the editor exits, its
1717
- content is copied back to the query buffer. If no <replaceable
1724
+ specified, the file is edited; after the editor exits, the file's
1725
+ content is copied into the current query buffer. If no <replaceable
1718
1726
class="parameter">filename</replaceable> is given, the current query
1719
1727
buffer is copied to a temporary file which is then edited in the same
1728
+ fashion. Or, if the current query buffer is empty, the most recently
1729
+ executed query is copied to a temporary file and edited in the same
1720
1730
fashion.
1721
1731
</para>
1722
1732
1723
1733
<para>
1724
- The new query buffer is then re-parsed according to the normal
1725
- rules of <application>psql</application>, where the whole buffer
1726
- is treated as a single line. (Thus you cannot make scripts this
1727
- way. Use <command>\i</command> for that.) This means that
1728
- if the query ends with (or contains) a semicolon, it is
1729
- immediately executed. Otherwise it will merely wait in the
1730
- query buffer; type semicolon or <literal>\g</> to send it, or
1731
- <literal>\r</> to cancel.
1734
+ The new contents of the query buffer are then re-parsed according to
1735
+ the normal rules of <application>psql</application>, treating the
1736
+ whole buffer as a single line. Any complete queries are immediately
1737
+ executed; that is, if the query buffer contains or ends with a
1738
+ semicolon, everything up to that point is executed. Whatever remains
1739
+ will wait in the query buffer; type semicolon or <literal>\g</> to
1740
+ send it, or <literal>\r</> to cancel it by clearing the query buffer.
1741
+ Treating the buffer as a single line primarily affects meta-commands:
1742
+ whatever is in the buffer after a meta-command will be taken as
1743
+ argument(s) to the meta-command, even if it spans multiple lines.
1744
+ (Thus you cannot make meta-command-using scripts this way.
1745
+ Use <command>\i</command> for that.)
1732
1746
</para>
1733
1747
1734
1748
<para>
@@ -1888,16 +1902,17 @@ Tue Oct 26 21:40:57 CEST 1999
1888
1902
<term><literal>\g [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
1889
1903
<listitem>
1890
1904
<para>
1891
- Sends the current query input buffer to the server, and
1892
- optionally stores the query's output in <replaceable
1893
- class="parameter">filename</replaceable> or pipes the output
1894
- to the shell command <replaceable
1895
- class="parameter">command</replaceable>. The file or command is
1896
- written to only if the query successfully returns zero or more tuples,
1897
- not if the query fails or is a non-data-returning SQL command.
1905
+ Sends the current query buffer to the server for execution.
1906
+ If an argument is given, the query's output is written to the named
1907
+ file or piped to the given shell command, instead of displaying it as
1908
+ usual. The file or command is written to only if the query
1909
+ successfully returns zero or more tuples, not if the query fails or
1910
+ is a non-data-returning SQL command.
1898
1911
</para>
1899
1912
<para>
1900
- A bare <literal>\g</literal> is essentially equivalent to a semicolon.
1913
+ If the current query buffer is empty, the most recently sent query is
1914
+ re-executed instead. Except for that behavior, <literal>\g</literal>
1915
+ without an argument is essentially equivalent to a semicolon.
1901
1916
A <literal>\g</literal> with argument is a <quote>one-shot</quote>
1902
1917
alternative to the <command>\o</command> command.
1903
1918
</para>
@@ -1922,7 +1937,7 @@ Tue Oct 26 21:40:57 CEST 1999
1922
1937
1923
1938
<listitem>
1924
1939
<para>
1925
- Sends the current query input buffer to the server, then treats
1940
+ Sends the current query buffer to the server, then treats
1926
1941
each column of each row of the query's output (if any) as a SQL
1927
1942
statement to be executed. For example, to create an index on each
1928
1943
column of <structname>my_table</>:
@@ -1955,6 +1970,10 @@ CREATE INDEX
1955
1970
timing, and other query execution features apply to each generated
1956
1971
query as well.
1957
1972
</para>
1973
+ <para>
1974
+ If the current query buffer is empty, the most recently sent query
1975
+ is re-executed instead.
1976
+ </para>
1958
1977
</listitem>
1959
1978
</varlistentry>
1960
1979
@@ -1964,7 +1983,7 @@ CREATE INDEX
1964
1983
1965
1984
<listitem>
1966
1985
<para>
1967
- Sends the current query input buffer to the server and stores the
1986
+ Sends the current query buffer to the server and stores the
1968
1987
query's output into <application>psql</> variables (see <xref
1969
1988
linkend="APP-PSQL-variables" endterm="APP-PSQL-variables-title">).
1970
1989
The query to be executed must return exactly one row. Each column of
@@ -1996,6 +2015,10 @@ hello 10
1996
2015
If the query fails or does not return one row,
1997
2016
no variables are changed.
1998
2017
</para>
2018
+ <para>
2019
+ If the current query buffer is empty, the most recently sent query
2020
+ is re-executed instead.
2021
+ </para>
1999
2022
</listitem>
2000
2023
</varlistentry>
2001
2024
@@ -2302,6 +2325,8 @@ lo_import 152801
2302
2325
<listitem>
2303
2326
<para>
2304
2327
Print the current query buffer to the standard output.
2328
+ If the current query buffer is empty, the most recently executed query
2329
+ is printed instead.
2305
2330
</para>
2306
2331
</listitem>
2307
2332
</varlistentry>
@@ -2970,9 +2995,11 @@ testdb=> <userinput>\setenv LESS -imx4F</userinput>
2970
2995
<term><literal>\w</literal> or <literal>\write</literal> <literal>|</><replaceable class="parameter">command</replaceable></term>
2971
2996
<listitem>
2972
2997
<para>
2973
- Outputs the current query buffer to the file <replaceable
2998
+ Writes the current query buffer to the file <replaceable
2974
2999
class="parameter">filename</replaceable> or pipes it to the shell
2975
3000
command <replaceable class="parameter">command</replaceable>.
3001
+ If the current query buffer is empty, the most recently executed query
3002
+ is written instead.
2976
3003
</para>
2977
3004
</listitem>
2978
3005
</varlistentry>
@@ -2988,6 +3015,10 @@ testdb=> <userinput>\setenv LESS -imx4F</userinput>
2988
3015
displayed with a header that includes the <literal>\pset title</>
2989
3016
string (if any), the time as of query start, and the delay interval.
2990
3017
</para>
3018
+ <para>
3019
+ If the current query buffer is empty, the most recently sent query
3020
+ is re-executed instead.
3021
+ </para>
2991
3022
</listitem>
2992
3023
</varlistentry>
2993
3024
0 commit comments