Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdbkU-00027A-J5 for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2019 14:39:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdbkS-0004JF-Vz for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2019 14:39:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdbkS-0004J8-N6 for pgsql-hackers@lists.postgresql.org; Wed, 19 Jun 2019 14:39:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdbkL-0003Ne-Pp for pgsql-hackers@lists.postgresql.org; Wed, 19 Jun 2019 14:39:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5JEdOsI006788; Wed, 19 Jun 2019 10:39:24 -0400 From: Tom Lane To: Adrian Klaver cc: Ken Tanzer , Tim Cross , Jeff Janes , pgsql-hackers@lists.postgresql.org Subject: Re: psql UPDATE field [tab] expands to DEFAULT? In-reply-to: <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com> References: <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Tue, 18 Jun 2019 18:03:18 -0700" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <6712.1560955037.0@sss.pgh.pa.us> Date: Wed, 19 Jun 2019 10:39:24 -0400 Message-ID: <6787.1560955164@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6712.1560955037.1@sss.pgh.pa.us> [ moving thread to -hackers ] So I propose the attached patch for fixing the clear bugs that have emerged in this discussion: don't confuse UPDATE ... SET ... with GUC-setting commands, and don't offer just DEFAULT in contexts where that's unlikely to be the only valid completion. 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. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-bogus-SET-completions.patch"; charset="us-ascii" Content-ID: <6712.1560955037.2@sss.pgh.pa.us> Content-Description: fix-bogus-SET-completions.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5e38f46..3530570 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3361,8 +3361,13 @@ psql_completion(const char *text, int start, int en= d) else if (HeadMatches("ALTER", "DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|= USER") && TailMatches("SET", MatchAny)) COMPLETE_WITH("FROM CURRENT", "TO"); - /* Suggest possible variable values */ - else if (TailMatches("SET", MatchAny, "TO|=3D")) + + /* + * Suggest possible variable values in SET variable TO|=3D, along with t= he + * preceding ALTER syntaxes. + */ + else if (TailMatches("SET", MatchAny, "TO|=3D") && + !TailMatches("UPDATE", MatchAny, "SET", MatchAny, "TO|=3D")) { /* special cased code for individual GUCs */ if (TailMatches("DateStyle", "TO|=3D")) @@ -3390,8 +3395,18 @@ psql_completion(const char *text, int start, int en= d) else if (guctype && strcmp(guctype, "bool") =3D=3D 0) COMPLETE_WITH("on", "off", "true", "false", "yes", "no", "1", "0", "DEFAULT"); - else - COMPLETE_WITH("DEFAULT"); + + /* + * Note: if we didn't recognize the GUC name, it's important to + * not offer any completions, as most likely we've misinterpreted + * the context and this isn't a GUC-setting command at all. If we + * did recognize the GUC but it's not enum or bool type, it still + * seems better to do nothing. We used to offer (only) "DEFAULT" + * as a possible completion, but that turns out to be a bad idea, + * because with a single completion libreadline will decide that + * that's the only legal text and throw away whatever the user + * might've typed already. + */ = if (guctype) free(guctype); ------- =_aaaaaaaaaa0--