Re: PATCH: psql tab completion for SELECT - Mailing list pgsql-hackers

From Edmund Horner
Subject Re: PATCH: psql tab completion for SELECT
Date
Msg-id CAMyN-kBmq+J4Eqh=MVDLhjOO077uQEkbQWfBHSNPGQAUuXG9fw@mail.gmail.com
Whole thread Raw
In response to Re: PATCH: psql tab completion for SELECT  (David Fetter <david@fetter.org>)
Responses Re: PATCH: psql tab completion for SELECT  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Fri, 8 Oct 2021 at 20:01, David Fetter <david@fetter.org> wrote:
On Sat, Sep 22, 2018 at 06:53:55PM +1200, Edmund Horner wrote:
> Hi all,
>
> Here are some rebased versions of the last two patches.  No changes in
> functionality, except a minor case sensitivity fix in the "completion
> after commas" patch.
>
> Edmund

I've rebased and updated these to be more principled about what
functions could be tab completed.

Still missing: tests.

What precisely is this supposed to do?
 
Hi David,

The main patch 0001 was to add completion for "SELECT <tab>" using attributes, functions, and a couple of hard-coded options.

The changes to _complete_from_query were so that simple_query (when used in addon mode, as for this feature) could have the current word interpolated into it.  This feature uses a schema query to get the function names, as they can be schema qualified, and an addon to get the column names, as they can't (they could be table-qualified, but that's hard when you don't know what the table aliases will be).  Previously existing queries using addons did not need to interpolate into them, but this one did, hence the change.

The second patch 0002 was to build on 0001 and add support for pressing <tab> after a comma while in the column list, i.e. when SELECT was the most recent major keyword (major being defined by the list of keywords in CurrentQueryPartMatches).

There's a bit of trickery around completing "," by adding a single space.  Without the space, the next <tab> will try to complete using the whole word including the part before the comma.

Regarding testing, I can't see any automated tests for tab completion.  Though it seems to me we could do it with a readline driver program of some sorts, if the current regression test scripts don't work interactively.

Cheers,
Edmund

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: BUG #17212: pg_amcheck fails on checking temporary relations
Next
From: "houzj.fnst@fujitsu.com"
Date:
Subject: RE: Failed transaction statistics to measure the logical replication progress