tab completion for alter extension

Started by Jeff Janesalmost 10 years ago3 messages
#1Jeff Janes
jeff.janes@gmail.com
1 attachment(s)

tab completion for "alter extension foobar update" yields a list of
tables. That is actively misleading. (This is not new in 9.6.)

It should complete to nothing, or "TO" followed by a list of available versions.

The attached patch takes approach 2. I thought of adding a ";" to the
list completions to signify you can optionally end the command
immediately after UPDATE and have it be a complete command. But I
thought perhaps that was too clever, and unprecedented.

Will add to commitfest-next

Cheers,

Jeff

Attachments:

alter_extension_update_tab.ctext/x-csrc; charset=US-ASCII; name=alter_extension_update_tab.cDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index a62ffe6..85f7a1c
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 820,825 ****
--- 820,832 ----
  "  WHERE (%d = pg_catalog.length('%s'))"\
  "    AND pg_catalog.quote_ident(name)='%s'"
  
+ /* the silly-looking length condition is just to eat up the current word */
+ #define Query_for_list_of_available_extension_versions_with_TO \
+ " SELECT 'TO ' || pg_catalog.quote_ident(version) "\
+ "   FROM pg_catalog.pg_available_extension_versions "\
+ "  WHERE (%d = pg_catalog.length('%s'))"\
+ "    AND pg_catalog.quote_ident(name)='%s'"
+ 
  #define Query_for_list_of_prepared_statements \
  " SELECT pg_catalog.quote_ident(name) "\
  "   FROM pg_catalog.pg_prepared_statements "\
*************** psql_completion(const char *text, int st
*** 1414,1419 ****
--- 1421,1440 ----
  	else if (Matches3("ALTER", "EXTENSION", MatchAny))
  		COMPLETE_WITH_LIST4("ADD", "DROP", "UPDATE", "SET SCHEMA");
  
+ 	/* ALTER EXTENSION <name> UPDATE */
+ 	else if (Matches4("ALTER", "EXTENSION", MatchAny, "UPDATE"))
+ 	{
+ 		completion_info_charp = prev2_wd;
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions_with_TO);
+ 	}
+ 
+ 	/* ALTER EXTENSION <name> UPDATE TO*/
+ 	else if (Matches5("ALTER", "EXTENSION", MatchAny, "UPDATE", "TO"))
+ 	{
+ 		completion_info_charp = prev3_wd;
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
+ 	}
+ 
  	/* ALTER FOREIGN */
  	else if (Matches2("ALTER", "FOREIGN"))
  		COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
#2Gerdan Santos
gerdan@gmail.com
In reply to: Jeff Janes (#1)
Re: tab completion for alter extension

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed

I did some tests and found nothing special. The stated resource is implemented correctly.
He passes all regression tests and enables the use of the new features specified.

The new status of this patch is: Ready for Committer

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gerdan Santos (#2)
Re: tab completion for alter extension

Gerdan Santos <gerdan@gmail.com> writes:

I did some tests and found nothing special. The stated resource is implemented correctly.
He passes all regression tests and enables the use of the new features specified.

The new status of this patch is: Ready for Committer

Pushed, thanks.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers