Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM

From: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
To: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: tab-completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM
Date: 2025-07-18 07:49:28
Message-ID: 20250718164928.f55ff231d8968c4cdeec6ac4@sraoss.co.jp
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 17 Jul 2025 10:57:36 +0900
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:

> On Tue, 17 Jun 2025 00:08:32 +0900
> Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
>
> > On Thu, 5 Jun 2025 16:52:00 +0900
> > Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
> >
> > > On Thu, 5 Jun 2025 10:08:35 +0900
> > > Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
> > >
> > > > Hi,
> > > >
> > > > Currently, tab completion for COPY only suggests filenames after TO or
> > > > FROM, even though STDIN, STDOUT, and PROGRAM are also valid syntax options.
> > > >
> > > > I'd like to propose improving the tab completion behavior as described in
> > > > the subject, so that these keywords are suggested appropriately, and filenames
> > > > are offered as potential command names after the PROGRAM keyword.
> > > >
> > > > I've attached this proposal as a patch series with the following three parts:
> > >
> > > I'm sorry but the previous patches were accidentally broken and didn't work.
> > > I've attached fixed patches.
> > >
> > > >
> > > > 0001: Refactor match_previous_words() to remove direct use of rl_completion_matches()
> > > >
> > > > This is a preparatory cleanup. Most completions in match_previous_words() already use
> > > > COMPLETE_WITH* macros, which wrap rl_completion_matches(). However, some direct calls
> > > > still remain.
> > > >
> > > > This patch replaces the remaining direct calls with COMPLETE_WITH_FILES or
> > > > COMPLETE_WITH_GENERATOR, improving consistency and readability.
> > > >
> > > > 0002: Add tab completion support for COPY ... TO/FROM STDIN, STDOUT, and PROGRAM
> > > >
> > > > This is the main patch. It extends tab completion to suggest STDIN, STDOUT, and PROGRAM
> > > > after TO or FROM. After PROGRAM, filenames are suggested as possible command names.
> > > >
> > > > To support this, a new macro COMPLETE_WITH_FILES_PLUS is introduced. This allows
> > > > combining literal keywords with filename suggestions in the completion list.
> > > >
> > > > 0003: Improve tab completion for COPY option lists
> > > >
> > > > Currently, only the first option in a parenthesized list is suggested during completion,
> > > > and nothing is suggested after a comma.
> > > >
> > > > This patch enables suggestions after each comma, improving usability when specifying
> > > > multiple options.
> > > >
> > > > Although not directly related to the main proposal, I believe this is a helpful enhancement
> > > > to COPY tab completion and included it here for completeness.
> > > >
> > > > I’d appreciate your review and feedback on this series.

The previous patch was broken failed to complie since I missed following
the required format of if-conditions in match_previous_words().
I've attached update patches.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
v5-0003-Improve-tab-completion-for-COPY-option-lists.patch text/x-diff 3.7 KB
v5-0002-Add-tab-completion-support-for-COPY-.-TO-FROM-STD.patch text/x-diff 7.9 KB
v5-0001-Refactor-match_previous_words-to-remove-direct-us.patch text/x-diff 4.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael J. Baars 2025-07-18 07:52:02 Lossless transmission of double precision floating point
Previous Message Ashutosh Bapat 2025-07-18 07:19:53 Re: meson and check-tests