Skip to content

Commit fc39b28

Browse files
committed
psql: Rename meta-command \close to \close_prepared
\close has been introduced in d55322b to be able to close a prepared statement using the extended protocol in psql. Per discussion, the name "close" is ambiguous. At the SQL level, CLOSE is used to close a cursor. At protocol level, the close message can be used to either close a statement or a portal. This patch renames \close to \close_prepared to avoid any ambiguity and make it clear that this is used to close a prepared statement. This new name has been chosen based on the feedback from the author and the reviewers. Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl> Discussion: https://postgr.es/m/3e694442-0df5-4f92-a08f-c5d4c4346b85@eisentraut.org
1 parent f3ed72c commit fc39b28

File tree

10 files changed

+34
-33
lines changed

10 files changed

+34
-33
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,8 @@ INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1
10671067
</listitem>
10681068
</varlistentry>
10691069

1070-
<varlistentry id="app-psql-meta-command-close">
1071-
<term><literal>\close</literal> <replaceable class="parameter">prepared_statement_name</replaceable></term>
1070+
<varlistentry id="app-psql-meta-command-close-prepared">
1071+
<term><literal>\close_prepared</literal> <replaceable class="parameter">prepared_statement_name</replaceable></term>
10721072

10731073
<listitem>
10741074
<para>
@@ -1081,7 +1081,7 @@ INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1
10811081
Example:
10821082
<programlisting>
10831083
SELECT $1 \parse stmt1
1084-
\close stmt1
1084+
\close_prepared stmt1
10851085
</programlisting>
10861086
</para>
10871087

@@ -3710,7 +3710,7 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
37103710
All queries executed while a pipeline is ongoing use the extended
37113711
query protocol. Queries are appended to the pipeline when ending with
37123712
a semicolon. The meta-commands <literal>\bind</literal>,
3713-
<literal>\bind_named</literal>, <literal>\close</literal> or
3713+
<literal>\bind_named</literal>, <literal>\close_prepared</literal> or
37143714
<literal>\parse</literal> can be used in an ongoing pipeline. While
37153715
a pipeline is ongoing, <literal>\sendpipeline</literal> will append
37163716
the current query buffer to the pipeline. Other meta-commands like

doc/src/sgml/release-18.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,7 @@ Author: Michael Paquier <michael@paquier.xyz>
27462746
<link
27472747
linkend="app-psql-meta-command-bind-named"><literal>\bind_named</literal></link>,
27482748
and <link
2749-
linkend="app-psql-meta-command-close"><literal>\close</literal></link>.
2749+
linkend="app-psql-meta-command-close-prepared"><literal>\close_prepared</literal></link>.
27502750
</para>
27512751
</listitem>
27522752

src/bin/psql/command.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ static backslashResult exec_command_C(PsqlScanState scan_state, bool active_bran
6767
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch);
6868
static backslashResult exec_command_cd(PsqlScanState scan_state, bool active_branch,
6969
const char *cmd);
70-
static backslashResult exec_command_close(PsqlScanState scan_state, bool active_branch,
71-
const char *cmd);
70+
static backslashResult exec_command_close_prepared(PsqlScanState scan_state,
71+
bool active_branch, const char *cmd);
7272
static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_branch);
7373
static backslashResult exec_command_copy(PsqlScanState scan_state, bool active_branch);
7474
static backslashResult exec_command_copyright(PsqlScanState scan_state, bool active_branch);
@@ -330,8 +330,8 @@ exec_command(const char *cmd,
330330
status = exec_command_connect(scan_state, active_branch);
331331
else if (strcmp(cmd, "cd") == 0)
332332
status = exec_command_cd(scan_state, active_branch, cmd);
333-
else if (strcmp(cmd, "close") == 0)
334-
status = exec_command_close(scan_state, active_branch, cmd);
333+
else if (strcmp(cmd, "close_prepared") == 0)
334+
status = exec_command_close_prepared(scan_state, active_branch, cmd);
335335
else if (strcmp(cmd, "conninfo") == 0)
336336
status = exec_command_conninfo(scan_state, active_branch);
337337
else if (pg_strcasecmp(cmd, "copy") == 0)
@@ -728,10 +728,10 @@ exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
728728
}
729729

730730
/*
731-
* \close -- close a previously prepared statement
731+
* \close_prepared -- close a previously prepared statement
732732
*/
733733
static backslashResult
734-
exec_command_close(PsqlScanState scan_state, bool active_branch, const char *cmd)
734+
exec_command_close_prepared(PsqlScanState scan_state, bool active_branch, const char *cmd)
735735
{
736736
backslashResult status = PSQL_CMD_SKIP_LINE;
737737

src/bin/psql/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ clean_extended_state(void)
26282628

26292629
switch (pset.send_mode)
26302630
{
2631-
case PSQL_SEND_EXTENDED_CLOSE: /* \close */
2631+
case PSQL_SEND_EXTENDED_CLOSE: /* \close_prepared */
26322632
free(pset.stmtName);
26332633
break;
26342634
case PSQL_SEND_EXTENDED_PARSE: /* \parse */

src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ slashUsage(unsigned short int pager)
331331
HELP0(" \\bind [PARAM]... set query parameters\n");
332332
HELP0(" \\bind_named STMT_NAME [PARAM]...\n"
333333
" set query parameters for an existing prepared statement\n");
334-
HELP0(" \\close STMT_NAME close an existing prepared statement\n");
334+
HELP0(" \\close_prepared STMT_NAME\n"
335+
" close an existing prepared statement\n");
335336
HELP0(" \\endpipeline exit pipeline mode\n");
336337
HELP0(" \\flush flush output data to the server\n");
337338
HELP0(" \\flushrequest send request to the server to flush its output buffer\n");

src/bin/psql/tab-complete.in.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ psql_completion(const char *text, int start, int end)
18751875
static const char *const backslash_commands[] = {
18761876
"\\a",
18771877
"\\bind", "\\bind_named",
1878-
"\\connect", "\\conninfo", "\\C", "\\cd", "\\close", "\\copy",
1878+
"\\connect", "\\conninfo", "\\C", "\\cd", "\\close_prepared", "\\copy",
18791879
"\\copyright", "\\crosstabview",
18801880
"\\d", "\\da", "\\dA", "\\dAc", "\\dAf", "\\dAo", "\\dAp",
18811881
"\\db", "\\dc", "\\dconfig", "\\dC", "\\dd", "\\ddp", "\\dD",

src/test/regress/expected/psql.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ LINE 1: SELECT $1, $2
160160
foo4 | bar4
161161
(1 row)
162162

163-
-- \close (extended query protocol)
164-
\close
165-
\close: missing required argument
166-
\close ''
167-
\close stmt2
168-
\close stmt2
163+
-- \close_prepared (extended query protocol)
164+
\close_prepared
165+
\close_prepared: missing required argument
166+
\close_prepared ''
167+
\close_prepared stmt2
168+
\close_prepared stmt2
169169
SELECT name, statement FROM pg_prepared_statements ORDER BY name;
170170
name | statement
171171
-------+----------------
@@ -4666,7 +4666,7 @@ bar 'bar' "bar"
46664666
\C arg1
46674667
\c arg1 arg2 arg3 arg4
46684668
\cd arg1
4669-
\close stmt1
4669+
\close_prepared stmt1
46704670
\conninfo
46714671
\copy arg1 arg2 arg3 arg4 arg5 arg6
46724672
\copyright

src/test/regress/expected/psql_pipeline.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,23 +564,23 @@ SELECT $1 \bind \sendpipeline
564564
SELECT $1 \bind 1 \sendpipeline
565565
SELECT $1 \parse a
566566
\bind_named a 1 \sendpipeline
567-
\close a
567+
\close_prepared a
568568
\flushrequest
569569
\getresults
570570
ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1
571571
-- Pipeline is aborted.
572572
SELECT $1 \bind 1 \sendpipeline
573573
SELECT $1 \parse a
574574
\bind_named a 1 \sendpipeline
575-
\close a
575+
\close_prepared a
576576
-- Sync allows pipeline to recover.
577577
\syncpipeline
578578
\getresults
579579
Pipeline aborted, command did not run
580580
SELECT $1 \bind 1 \sendpipeline
581581
SELECT $1 \parse a
582582
\bind_named a 1 \sendpipeline
583-
\close a
583+
\close_prepared a
584584
\flushrequest
585585
\getresults
586586
?column?

src/test/regress/sql/psql.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ SELECT $1, $2 \parse stmt3
6868
-- Multiple \g calls mean multiple executions
6969
\bind_named stmt2 'foo3' \g \bind_named stmt3 'foo4' 'bar4' \g
7070

71-
-- \close (extended query protocol)
72-
\close
73-
\close ''
74-
\close stmt2
75-
\close stmt2
71+
-- \close_prepared (extended query protocol)
72+
\close_prepared
73+
\close_prepared ''
74+
\close_prepared stmt2
75+
\close_prepared stmt2
7676
SELECT name, statement FROM pg_prepared_statements ORDER BY name;
7777

7878
-- \bind (extended query protocol)
@@ -1035,7 +1035,7 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
10351035
\C arg1
10361036
\c arg1 arg2 arg3 arg4
10371037
\cd arg1
1038-
\close stmt1
1038+
\close_prepared stmt1
10391039
\conninfo
10401040
\copy arg1 arg2 arg3 arg4 arg5 arg6
10411041
\copyright

src/test/regress/sql/psql_pipeline.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,21 @@ SELECT $1 \bind \sendpipeline
306306
SELECT $1 \bind 1 \sendpipeline
307307
SELECT $1 \parse a
308308
\bind_named a 1 \sendpipeline
309-
\close a
309+
\close_prepared a
310310
\flushrequest
311311
\getresults
312312
-- Pipeline is aborted.
313313
SELECT $1 \bind 1 \sendpipeline
314314
SELECT $1 \parse a
315315
\bind_named a 1 \sendpipeline
316-
\close a
316+
\close_prepared a
317317
-- Sync allows pipeline to recover.
318318
\syncpipeline
319319
\getresults
320320
SELECT $1 \bind 1 \sendpipeline
321321
SELECT $1 \parse a
322322
\bind_named a 1 \sendpipeline
323-
\close a
323+
\close_prepared a
324324
\flushrequest
325325
\getresults
326326
\endpipeline

0 commit comments

Comments
 (0)