Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQO3g-00060p-TG for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Sep 2021 06:06:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQO3f-0001G1-KL for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Sep 2021 06:06:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQO3f-0001Ft-1u for pgsql-hackers@lists.postgresql.org; Wed, 15 Sep 2021 06:06:11 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQO3b-0005tc-Lo for pgsql-hackers@postgresql.org; Wed, 15 Sep 2021 06:06:10 +0000 Received: by fetter.org (Postfix, from userid 1001) id 4D08340E28; Wed, 15 Sep 2021 08:06:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fetter.org; s=default; t=1631685965; bh=A0+3ppef8/myc7GXcBOvX1JCRTK7LBSCs4/3pSZnY/M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S6SWgsK37xfSwnijyA10kH5o/u+0yoprbT5baGr55TGbUuZ7fYzEZ+MyktOda1qDK ylxdPPmw3vKwRNVwy+S4YUl7kVVF3C8eyINkRnyvzsr01e921/hi/H1GFG9VYrLphq tiLyeHWzcTrYmy7tIEmBTQcIGjt1C/+XoLnLSSsLQrFDAPANf5hQwtJa5DbI2a1v+7 CU6UD+Cys0oQAhWKeiibaSnMq5Ph1dseB4eAYXLcwsKTNAqimMB5A1rMgEko3KiOKT PXwnE2hylE2KNxIgNJoxByTvM545R0cx2KjIdSAzdjvHFikeZnphOi4N5Hu36bGcpJ ao3KH+n6vdc4Q== Date: Wed, 15 Sep 2021 06:06:04 +0000 From: David Fetter To: Daniel Gustafsson Cc: Michael Paquier , Aleksander Alekseev , PostgreSQL Development Subject: Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ... Message-ID: <20210915060604.GG18391@fetter.org> References: <20210427002433.GB17834@fetter.org> <7C4FA245-31C8-4314-8CC3-692EC7917F63@yesql.se> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Ns7jmDPpOpCD+GE/" Content-Disposition: inline In-Reply-To: <7C4FA245-31C8-4314-8CC3-692EC7917F63@yesql.se> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Ns7jmDPpOpCD+GE/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Sep 03, 2021 at 08:27:55PM +0200, Daniel Gustafsson wrote: > > On 19 May 2021, at 09:53, Michael Paquier wrote: > > > > On Tue, Apr 27, 2021 at 12:58:52PM +0300, Aleksander Alekseev wrote: > >> I've noticed there is no tab completion for ALTER TABLE xxx ADD. Here > >> is an alternative version of the patch that fixes this as well. Not > >> sure if this should be in the same commit though. > > > > - /* If we have ALTER TABLE DROP, provide COLUMN or CONSTRAINT */ > > - else if (Matches("ALTER", "TABLE", MatchAny, "DROP")) > > + /* If we have ALTER TABLE ADD|DROP, provide COLUMN or CONSTRAINT */ > > + else if (Matches("ALTER", "TABLE", MatchAny, "ADD|DROP")) > > Seems to me that the behavior to not complete with COLUMN or > > CONSTRAINT for ADD is intentional, as it is possible to specify a > > constraint or column name without the object type first. This > > introduces a inconsistent behavior with what we do for columns with > > ADD, for one. So a more consistent approach would be to list columns, > > constraints, COLUMN and CONSTRAINT in the list of options available > > after ADD. > > > > + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT")) > > + { > > + completion_info_charp = prev3_wd; > > + COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table); > > + } > > Specifying valid constraints is an authorized grammar, so it does not > > seem that bad to keep things as they are, either. I would leave that > > alone. > > This has stalled being marked Waiting on Author since May, and reading the > above it sounds like marking it Returned with Feedback is the logical next step > (patch also no longer applies). Please find attached the next revision :) Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate --Ns7jmDPpOpCD+GE/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-psql-Fix-tab-completion-for-ALTER-TABLE.patch" From 716e9dde96ef9973fc6b0fc9ca9934df153af9da Mon Sep 17 00:00:00 2001 From: David Fetter Date: Tue, 14 Sep 2021 15:28:34 -0700 Subject: [PATCH v4] psql: Fix tab completion for ALTER TABLE... ... VALIDATE CONSTRAINT. Completions now include only constraints which have not yet been validated. --- src/bin/psql/tab-complete.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git src/bin/psql/tab-complete.c src/bin/psql/tab-complete.c index 5cd5838668..b55166aa64 100644 --- src/bin/psql/tab-complete.c +++ src/bin/psql/tab-complete.c @@ -788,6 +788,15 @@ Query_for_index_of_table \ " and pg_catalog.quote_ident(c1.relname)='%s'"\ " and pg_catalog.pg_table_is_visible(c1.oid)" +/* the silly-looking length condition is just to eat up the current word */ +#define Query_for_constraint_of_table_not_validated \ +"SELECT pg_catalog.quote_ident(conname) "\ +" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\ +" WHERE c1.oid=conrelid and (%d = pg_catalog.length('%s'))"\ +" and pg_catalog.quote_ident(c1.relname)='%s'"\ +" and pg_catalog.pg_table_is_visible(c1.oid)" \ +" and NOT con.convalidated" + #define Query_for_all_table_constraints \ "SELECT pg_catalog.quote_ident(conname) "\ " FROM pg_catalog.pg_constraint c "\ @@ -2145,14 +2154,22 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_ATTR(prev3_wd, ""); /* - * If we have ALTER TABLE ALTER|DROP|RENAME|VALIDATE CONSTRAINT, + * If we have ALTER TABLE ALTER|DROP|RENAME CONSTRAINT, * provide list of constraints */ - else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT")) + else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT")) { completion_info_charp = prev3_wd; COMPLETE_WITH_QUERY(Query_for_constraint_of_table); } + /* + * ALTER TABLE VALIDATE CONSTRAINT + */ + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT")) + { + completion_info_charp = prev3_wd; + COMPLETE_WITH_QUERY(Query_for_constraint_of_table_not_validated); + } /* ALTER TABLE ALTER [COLUMN] */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) || Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny)) -- 2.31.1 --Ns7jmDPpOpCD+GE/--