v13-0003-Add-tab-completion-for-the-WAIT-FOR-LSN-MODE-opt.patch
application/octet-stream
Filename: v13-0003-Add-tab-completion-for-the-WAIT-FOR-LSN-MODE-opt.patch
Type: application/octet-stream
Part: 2
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v13-0003
Subject: Add tab completion for the WAIT FOR LSN MODE option
| File | + | − |
|---|---|---|
| src/bin/psql/tab-complete.in.c | 17 | 11 |
From 1d1ee0be7975a94e0f062a96e77be11322f335fa Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Sat, 3 Jan 2026 00:42:32 +0200
Subject: [PATCH v13 3/4] Add tab completion for the WAIT FOR LSN MODE option
Update psql tab completion to support the optional MODE option in the
WAIT FOR LSN command. After specifying an LSN value, completion now offers
both MODE and WITH keywords. The MODE option specifies which LSN type to wait
for. In particular, it controls whether the wait is evaluated from the
standby or primary perspective.
When MODE is specified, the completion suggests the valid mode values:
standby_replay, standby_write, standby_flush, and primary_flush.
Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
---
src/bin/psql/tab-complete.in.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index d81f2fcdbe6..06edea98f06 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -5355,8 +5355,11 @@ match_previous_words(int pattern_id,
/*
* WAIT FOR LSN '<lsn>' [ WITH ( option [, ...] ) ]
* where option can be:
+ * MODE '<mode>'
* TIMEOUT '<timeout>'
* NO_THROW
+ * and mode can be:
+ * standby_replay | standby_write | standby_flush | primary_flush
*/
else if (Matches("WAIT"))
COMPLETE_WITH("FOR");
@@ -5369,21 +5372,24 @@ match_previous_words(int pattern_id,
COMPLETE_WITH("WITH");
else if (Matches("WAIT", "FOR", "LSN", MatchAny, "WITH"))
COMPLETE_WITH("(");
+
+ /*
+ * Handle parenthesized option list. This fires when we're in an
+ * unfinished parenthesized option list. get_previous_words treats a
+ * completed parenthesized option list as one word, so the above test is
+ * correct.
+ *
+ * 'mode' takes a string value (one of the listed above), 'timeout' takes
+ * a string value, and 'no_throw' takes no value. We do not offer
+ * completions for the *values* of 'timeout' or 'no_throw'.
+ */
else if (HeadMatches("WAIT", "FOR", "LSN", MatchAny, "WITH", "(*") &&
!HeadMatches("WAIT", "FOR", "LSN", MatchAny, "WITH", "(*)"))
{
- /*
- * This fires if we're in an unfinished parenthesized option list.
- * get_previous_words treats a completed parenthesized option list as
- * one word, so the above test is correct.
- */
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
- COMPLETE_WITH("timeout", "no_throw");
-
- /*
- * timeout takes a string value, no_throw takes no value. We don't
- * offer completions for these values.
- */
+ COMPLETE_WITH("mode", "timeout", "no_throw");
+ else if (TailMatches("mode"))
+ COMPLETE_WITH("'standby_replay'", "'standby_write'", "'standby_flush'", "'primary_flush'");
}
/* WITH [RECURSIVE] */
--
2.39.5 (Apple Git-154)