pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH] ALTER tab completion
4+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2021-11-29 f44ceb46ec  Improve psql tab completion for views, FDWs, sequences and transforms
* [PATCH] ALTER tab completion
@ 2021-11-26 04:55  Ken Kato <katouknl@oss.nttdata.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Ken Kato @ 2021-11-26 04:55 UTC (permalink / raw)
  To: pgsql-hackers@lists.postgresql.org

Hi hackers,

I noticed that there are some tab completions missing for the following 
commands:
-ALTER DEFAULT PRIVILEGES: missing FOR USER
-ALTER FOREIGN DATA WRAPPER: missing NO HANDLER, NO VALIDATOR
-ALTER SEQUENCE: missing AS
-ALTER VIEW: no completion after ALTER COLUMN column_name
-ALTER TRANSFORM: no doc for ALTER TRANSFORM, so I excluded TRANSFORM 
from ALTER tab completion

I made a patch for this, so please have a look.

Best wishes,

-- 
Ken Kato
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments:

alter_tab_completion.patch (text/x-diff, 3.4K) download diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 4f724e4428..60bbd18ade 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 <name> */ 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 <name> */ else if (Matches("ALTER", "FOREIGN", "TABLE", MatchAny)) @@ -1856,10 +1859,10 @@ psql_completion(const char *text, int start, int end) /* ALTER DEFAULT PRIVILEGES */ else if (Matches("ALTER", "DEFAULT", "PRIVILEGES")) - COMPLETE_WITH("FOR ROLE", "IN SCHEMA"); + COMPLETE_WITH("FOR ROLE", "FOR USER", "IN SCHEMA"); /* ALTER DEFAULT PRIVILEGES FOR */ else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "FOR")) - COMPLETE_WITH("ROLE"); + COMPLETE_WITH("ROLE", "USER"); /* ALTER DEFAULT PRIVILEGES IN */ else if (Matches("ALTER", "DEFAULT", "PRIVILEGES", "IN")) COMPLETE_WITH("SCHEMA"); @@ -1907,9 +1910,12 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH("DEFAULT", "NOT NULL", "SCHEMA"); /* ALTER SEQUENCE <name> */ 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 <name> AS */ + else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS")) + COMPLETE_WITH("smallint", "integer", "bigint"); /* ALTER SEQUENCE <name> NO */ else if (Matches("ALTER", "SEQUENCE", MatchAny, "NO")) COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); @@ -1938,9 +1944,15 @@ psql_completion(const char *text, int start, int end) /* ALTER VIEW xxx RENAME yyy */ else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", MatchAnyExcept("TO"))) COMPLETE_WITH("TO"); + /* ALTER VIEW xxx ALTER yyy */ + else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny)) + COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT"); /* ALTER VIEW xxx RENAME COLUMN yyy */ else if (Matches("ALTER", "VIEW", MatchAny, "RENAME", "COLUMN", MatchAnyExcept("TO"))) COMPLETE_WITH("TO"); + /* ALTER VIEw xxx ALTER COLUMN yyy */ + else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", "COLUMN", MatchAny)) + COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT"); /* ALTER MATERIALIZED VIEW <name> */ else if (Matches("ALTER", "MATERIALIZED", "VIEW", MatchAny))
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: [PATCH] ALTER tab completion
@ 2021-11-26 06:33  Michael Paquier <michael@paquier.xyz>
  parent: Ken Kato <katouknl@oss.nttdata.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael Paquier @ 2021-11-26 06:33 UTC (permalink / raw)
  To: Ken Kato <katouknl@oss.nttdata.com>; +Cc: pgsql-hackers@lists.postgresql.org

On Fri, Nov 26, 2021 at 01:55:46PM +0900, Ken Kato wrote:
> I noticed that there are some tab completions missing for the following
> commands:
> -ALTER DEFAULT PRIVILEGES: missing FOR USER

FOR ROLE is an equivalent.  That does not seem mandatory to me.

> -ALTER FOREIGN DATA WRAPPER: missing NO HANDLER, NO VALIDATOR

Okay for this one.

> -ALTER VIEW: no completion after ALTER COLUMN column_name

+   /* ALTER VIEW xxx ALTER yyy */
+   else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny))
+       COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT");
It may be cleaner to group this one with "ALTER VIEW xxx ALTER yyy"
two blocks above.

> -ALTER TRANSFORM: no doc for ALTER TRANSFORM, so I excluded TRANSFORM from
> ALTER tab completion

Right.

> -ALTER SEQUENCE: missing AS
+   /* ALTER SEQUENCE <name> AS */
+   else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS"))
+       COMPLETE_WITH("smallint", "integer", "bigint");
Re-quoting Horiguchi-san, that should be COMPLETE_WITH_CS() to keep
these completions in lower case.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [PATCH] ALTER tab completion
@ 2021-11-26 08:00  Ken Kato <katouknl@oss.nttdata.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 4+ messages in thread

From: Ken Kato @ 2021-11-26 08:00 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-hackers@lists.postgresql.org

Hi,

Thank you for the comments!

I made following updates:

>> -ALTER DEFAULT PRIVILEGES: missing FOR USER
> 
> FOR ROLE is an equivalent.  That does not seem mandatory to me.
I deleted the completion for "FOR USER".

>> -ALTER VIEW: no completion after ALTER COLUMN column_name
> +   /* ALTER VIEW xxx ALTER yyy */
> +   else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny))
> +       COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT");
> It may be cleaner to group this one with "ALTER VIEW xxx ALTER yyy"
> two blocks above.
I put them back to back so that it looks cleaner.

>> -ALTER SEQUENCE: missing AS
> +   /* ALTER SEQUENCE <name> AS */
> +   else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS"))
> +       COMPLETE_WITH("smallint", "integer", "bigint");
> Re-quoting Horiguchi-san, that should be COMPLETE_WITH_CS() to keep
> these completions in lower case.
That's what it's for.
I used COMPLETE_WITH_CS instead of COMPLETE_WITH.

Best wishes,

-- 
Ken Kato
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments:

alter_tab_completion.patch (text/x-diff, 2.8K) download diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index fa2e19593c..4cc32ac0ba 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 <name> */ 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 <name> */ 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 <name> */ 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 <name> AS */ + else if (TailMatches("ALTER", "SEQUENCE", MatchAny, "AS")) + COMPLETE_WITH_CS("smallint", "integer", "bigint"); /* ALTER SEQUENCE <name> NO */ else if (Matches("ALTER", "SEQUENCE", MatchAny, "NO")) COMPLETE_WITH("MINVALUE", "MAXVALUE", "CYCLE"); @@ -1935,6 +1941,12 @@ 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 yyy */ + else if (Matches("ALTER", "VIEW", MatchAny, "ALTER", MatchAny)) + COMPLETE_WITH("SET DEFAULT", "DROP DEFAULT"); + /* ALTER VIEW xxx ALTER COLUMN yyy */ + else if (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");
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: [PATCH] ALTER tab completion
@ 2021-11-29 02:58  Michael Paquier <michael@paquier.xyz>
  parent: Ken Kato <katouknl@oss.nttdata.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Paquier @ 2021-11-29 02:58 UTC (permalink / raw)
  To: Ken Kato <katouknl@oss.nttdata.com>; +Cc: pgsql-hackers@lists.postgresql.org

On Fri, Nov 26, 2021 at 05:00:44PM +0900, Ken Kato wrote:
> I made following updates:

I have made one small modification for ALTER VIEW, and applied what
you have.  Thanks, Kato-san.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-11-29 02:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 04:55 [PATCH] ALTER tab completion Ken Kato <katouknl@oss.nttdata.com>
2021-11-26 06:33 ` Michael Paquier <michael@paquier.xyz>
2021-11-26 08:00   ` Ken Kato <katouknl@oss.nttdata.com>
2021-11-29 02:58     ` Michael Paquier <michael@paquier.xyz>

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