pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Ken Tanzer <ken.tanzer@gmail.com>
Cc: Tim Cross <theophilusx@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: psql UPDATE field [tab] expands to DEFAULT?
Date: Thu, 20 Jun 2019 14:51:50 -0400
Message-ID: <19529.1561056710@sss.pgh.pa.us> (raw)
In-Reply-To: <6787.1560955164@sss.pgh.pa.us>
References: <CAD3a31XpXzrZA9TT3BqLSHghdTK+=cXjNCE+oL2Zn4+oWoc=qA@mail.gmail.com>
	<b70db19f-d582-0d1a-5b4d-15ea385781a4@aklaver.com>
	<CAD3a31XEaeB2odBznuwv3xfshSAzUMPc1yEzGbZezRfQf-+hCA@mail.gmail.com>
	<067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com>
	<6787.1560955164@sss.pgh.pa.us>

I wrote:
> Nosing around in tab-complete.c, I notice a fair number of other
> places where we're doing COMPLETE_WITH() with just a single possible
> completion.  Knowing what we know now, in each one of those places
> libreadline will suppose that that completion is the only syntactically
> legal continuation, and throw away anything else the user might've typed.
> We should probably inspect each of those places to see if that's really
> desirable behavior ... but I didn't muster the energy to do that this
> morning.

I took a closer look and realized that this isn't some magic behavior of
arcane parts of libreadline; it's more like self-inflicted damage.  It
happens because tab-complete.c's complete_from_const() is doing exactly
what its comment says it does:

/*
 * This function returns one fixed string the first time even if it doesn't
 * match what's there, and nothing the second time. This should be used if
 * there is only one possibility that can appear at a certain spot, so
 * misspellings will be overwritten.  The string to be passed must be in
 * completion_charp.
 */

This is unlike complete_from_list(), which will only return completions
that match the text-string-so-far.

I have to wonder whether complete_from_const()'s behavior is really
a good idea; I think there might be an argument for getting rid of it
and using complete_from_list() even for one-element lists.

We certainly didn't do anybody any favors in the refactoring we did in
4f3b38fe2, which removed the source-code difference between calling
complete_from_const() and calling complete_from_list() with just one list
item.  But even before that, I really doubt that many people hacking on
tab-complete.c had internalized the idea that COMPLETE_WITH_CONST()
implied a higher degree of certainty than COMPLETE_WITH_LIST() with one
list item.  I'm pretty sure I'd never understood that.

Both of those functions go back to the beginnings of tab-complete.c,
so there's not much available in the history to explain the difference
in behavior (and the discussion of the original patch, if any, is lost
to the mists of time --- our archives for pgsql-patches only go back to
2000).  But my own feeling about this is that there's no situation in
which I'd expect tab completion to wipe out text I'd typed.

Thoughts?

			regards, tom lane





view thread (14+ messages)  latest in thread

Message-ID: <19529.1561056710@sss.pgh.pa.us>
Permalink:  ../19529.1561056710@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19529.1561056710@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, ken.tanzer@gmail.com, theophilusx@gmail.com, jeff.janes@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: psql UPDATE field [tab] expands to DEFAULT?
  In-Reply-To: <19529.1561056710@sss.pgh.pa.us>
  References: <CAD3a31XpXzrZA9TT3BqLSHghdTK+=cXjNCE+oL2Zn4+oWoc=qA@mail.gmail.com> <b70db19f-d582-0d1a-5b4d-15ea385781a4@aklaver.com> <CAD3a31XEaeB2odBznuwv3xfshSAzUMPc1yEzGbZezRfQf-+hCA@mail.gmail.com> <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com> <6787.1560955164@sss.pgh.pa.us> <19529.1561056710@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox