tab completion for extension versions
This patch adds "VERSION" to the list of words completed after "create
extension foo", and adds the list of available versions of foo after
"create extension foo version".
There is no point in filtering out the already installed version, as the
entire statement is doomed already if any version of the extension is
already installed.
Cheers,
Jeff
Attachments:
create_extension_version_tabcomplete_v1.patchapplication/octet-stream; name=create_extension_version_tabcomplete_v1.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 1619de5..4eb5058
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 729,734 ****
--- 729,741 ----
" FROM pg_catalog.pg_available_extensions "\
" WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s' AND installed_version IS NULL"
+ /* the silly-looking length condition is just to eat up the current word */
+ #define Query_for_list_of_available_extension_versions \
+ " SELECT 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
*** 2266,2275 ****
pg_strcasecmp(prev2_wd, "EXTENSION") == 0)
{
static const char *const list_CREATE_EXTENSION[] =
! {"WITH SCHEMA", "CASCADE", NULL};
COMPLETE_WITH_LIST(list_CREATE_EXTENSION);
}
/* CREATE FOREIGN */
else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
--- 2273,2290 ----
pg_strcasecmp(prev2_wd, "EXTENSION") == 0)
{
static const char *const list_CREATE_EXTENSION[] =
! {"WITH SCHEMA", "CASCADE", "VERSION", NULL};
COMPLETE_WITH_LIST(list_CREATE_EXTENSION);
}
+ /* CREATE EXTENSION <name> VERSION */
+ else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+ pg_strcasecmp(prev3_wd, "EXTENSION") == 0 &&
+ pg_strcasecmp(prev_wd, "VERSION") == 0)
+ {
+ completion_info_charp = prev2_wd;
+ COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
+ }
/* CREATE FOREIGN */
else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
On Sun, Oct 18, 2015 at 6:59 PM, Jeff Janes <jeff.janes@gmail.com> wrote:
This patch adds "VERSION" to the list of words completed after "create
extension foo", and adds the list of available versions of foo after "create
extension foo version".There is no point in filtering out the already installed version, as the
entire statement is doomed already if any version of the extension is
already installed.
Makes sense to me. Committed.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers