From f44ceb46ec2d8da48f6e145bf462d5620c25e079 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 29 Nov 2021 10:28:29 +0900 Subject: [PATCH] Improve psql tab completion for views, FDWs, sequences and transforms The following improvements are done: - Addition of type completion for ALTER SEQUENCE AS. - Ignore ALTER for transforms, as the command is not supported. - Addition of more completion for ALTER FOREIGN DATA WRAPPER. - Addition of options related to columns in ALTER VIEW. This is a continuation of the work done in 0cd6d3b. Author: Ken Kato Discussion: https://postgr.es/m/9497ae9ca1b31eb9b1e97aded1c2ab07@oss.nttdata.com --- src/bin/psql/tab-complete.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index fa2e19593c5..630026da2f9 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1088,7 +1088,7 @@ static const pgsql_thing_t words_after_create[] = { {"TEMPORARY", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE TEMPORARY * TABLE ... */ {"TEXT SEARCH", NULL, NULL, NULL}, - {"TRANSFORM", NULL, NULL, NULL}, + {"TRANSFORM", NULL, NULL, NULL, THING_NO_ALTER}, {"TRIGGER", "SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger WHERE substring(pg_catalog.quote_ident(tgname),1,%d)='%s' AND NOT tgisinternal"}, {"TYPE", NULL, NULL, &Query_for_list_of_datatypes}, {"UNIQUE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER}, /* for CREATE UNIQUE @@ -1754,7 +1754,10 @@ psql_completion(const char *text, int start, int end) /* ALTER FOREIGN DATA WRAPPER */ else if (Matches("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny)) - COMPLETE_WITH("HANDLER", "VALIDATOR", "OPTIONS", "OWNER TO", "RENAME TO"); + COMPLETE_WITH("HANDLER", "VALIDATOR", "NO", + "OPTIONS", "OWNER TO", "RENAME TO"); + else if (Matches("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny, "NO")) + COMPLETE_WITH("HANDLER", "VALIDATOR"); /* ALTER FOREIGN TABLE */ else if (Matches("ALTER", "FOREIGN", "TABLE", MatchAny)) @@ -1907,9 +1910,12 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("DEFAULT", "NOT NULL", "SCHEMA"); /* ALTER SEQUENCE */ else if (Matches("ALTER", "SEQUENCE", MatchAny)) - COMPLETE_WITH("INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", "NO", - "CACHE", "CYCLE", "SET SCHEMA", "OWNED BY", "OWNER TO", - "RENAME TO"); + COMPLETE_WITH("AS", "INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", + "NO", "CACHE", "CYCLE", "SET SCHEMA", "OWNED BY", + "OWNER TO", "RENAME TO"); + /* ALTER SEQUENCE AS */ + else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS")) + COMPLETE_WITH_CS("smallint", "integer", "bigint"); /* ALTER SEQUENCE NO */ else if (Matches("ALTER", "SEQUENCE", MatchAny, "NO")) COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); @@ -1935,6 +1941,10 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'TO'"); else if (Matches("ALTER", "VIEW", MatchAny, "ALTER|RENAME", "COLUMN")) COMPLETE_WITH_ATTR(prev3_wd, ""); + /* ALTER VIEW xxx ALTER [ COLUMN ] yyy */ + else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny) || + Matches("ALTER", "VIEW", MatchAny, "ALTER", "COLUMN", MatchAny)) + COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT"); /* ALTER VIEW xxx RENAME yyy */ else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", MatchAnyExcept("TO"))) COMPLETE_WITH("TO");