pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Fetter <david@fetter.org>
To: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
Date: Tue, 27 Apr 2021 00:24:34 +0000
Message-ID: <20210427002433.GB17834@fetter.org> (raw)

Folks,

I noticed that $subject completes with already valid constraints,
please find attached a patch that fixes it. I noticed that there are
other places constraints can be validated, but didn't check whether
similar bugs exist there yet.

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachments:

v1-0001-tab-completion-of-ALTER-TABLE.VALIDATE-CONSTRAINT.patch (text/x-diff, 2.3K) download From e191928111a7500c3a3bc84558797fe86451c24b Mon Sep 17 00:00:00 2001 From: David Fetter <david@fetter.org> Date: Mon, 26 Apr 2021 17:17:15 -0700 Subject: [PATCH v1] tab-completion of ALTER TABLE...VALIDATE CONSTRAINT To: hackers MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.30.2" This is a multi-part message in MIME format. --------------2.30.2 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit ...now chooses only among constraints that aren't already valid. diff --git src/bin/psql/tab-complete.c src/bin/psql/tab-complete.c index 7c4933333b..2252b7d3ac 100644 --- src/bin/psql/tab-complete.c +++ src/bin/psql/tab-complete.c @@ -785,6 +785,15 @@ static const SchemaQuery Query_for_list_of_collations = { " 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_nonvalid_constraint_of_table \ +"SELECT pg_catalog.quote_ident(conname) "\ +" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\ +" WHERE c1.oid=conrelid and and not convalidated"\ +" and (%d = pg_catalog.length('%s'))"\ +" and pg_catalog.quote_ident(c1.relname)='%s'"\ +" and pg_catalog.pg_table_is_visible(c1.oid)" + #define Query_for_all_table_constraints \ "SELECT pg_catalog.quote_ident(conname) "\ " FROM pg_catalog.pg_constraint c "\ @@ -2118,11 +2127,16 @@ psql_completion(const char *text, int start, int end) * If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE 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); } + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT")) + { + completion_info_charp = prev3_wd; + COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table); + } /* ALTER TABLE ALTER [COLUMN] <foo> */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) || Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny)) --------------2.30.2--

view thread (10+ messages)  latest in thread

Message-ID: <20210427002433.GB17834@fetter.org>
Permalink:  ../20210427002433.GB17834@fetter.org/
Also on:    postgresql.org/message-id/20210427002433.GB17834@fetter.org

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: david@fetter.org
  Subject: Re: Bug fix for tab completion of ALTER TABLE ... VALIDATE CONSTRAINT ...
  In-Reply-To: <20210427002433.GB17834@fetter.org>

* 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