Skip to content

Commit 662dbe2

Browse files
committed
Simplify tab completion of extension versions.
Second thoughts about 9cd43f6: given that we're staying bug-compatible with the old behavior of using double not single quotes for extension versions, we can simplify this completion code by pretending that extension versions *are* identifiers, and not using VERBATIM. Then _complete_from_query() will think that the query results are identifiers in need of quoting, and we end up with the same behavior as before. This doesn't work for Query_for_list_of_available_extension_versions_with_TO, but let's just drop that: there is no other place where we handle multi-keyword phrases that way, and it doesn't seem very desirable here either. Handle completion of "UPDATE TO" in our more usual pattern. Discussion: https://postgr.es/m/CAMkU=1yV+egSYrzWvbDY8VZ6bKEMrKbzxr-HTuiHi+wDgSUMgA@mail.gmail.com
1 parent 75bfe74 commit 662dbe2

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/bin/psql/tab-complete.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ static bool completion_force_quote; /* true to force-quote filenames */
239239
* 4) The list of attributes of the given table (possibly schema-qualified).
240240
* 5) The list of arguments to the given function (possibly schema-qualified).
241241
*
242-
* The query is generally expected to return raw SQL identifiers; quoting
243-
* is handled by the matching machinery. If what is returned is not SQL
244-
* identifiers, use one of the VERBATIM forms (and then, if quoting is
245-
* needed, do it inside the query).
242+
* The query is generally expected to return raw SQL identifiers; matching
243+
* to what the user typed is done in a quoting-aware fashion. If what is
244+
* returned is not SQL identifiers, use one of the VERBATIM forms, in which
245+
* case the query results are matched to the user's text without double-quote
246+
* processing (so if quoting is needed, you must provide it in the query
247+
* results).
246248
*/
247249
#define COMPLETE_WITH_QUERY(query) \
248250
COMPLETE_WITH_QUERY_LIST(query, NULL)
@@ -1081,19 +1083,10 @@ static const SchemaQuery Query_for_trigger_of_table = {
10811083
" FROM pg_catalog.pg_available_extensions "\
10821084
" WHERE name LIKE '%s' AND installed_version IS NULL"
10831085

1084-
/* the result of this query is not a raw identifier, so use VERBATIM */
10851086
#define Query_for_list_of_available_extension_versions \
1086-
" SELECT pg_catalog.quote_ident(version) "\
1087+
" SELECT version "\
10871088
" FROM pg_catalog.pg_available_extension_versions "\
1088-
" WHERE pg_catalog.quote_ident(version) LIKE '%s'"\
1089-
" AND name='%s'"
1090-
1091-
/* the result of this query is not a raw identifier, so use VERBATIM */
1092-
#define Query_for_list_of_available_extension_versions_with_TO \
1093-
" SELECT 'TO ' || pg_catalog.quote_ident(version) "\
1094-
" FROM pg_catalog.pg_available_extension_versions "\
1095-
" WHERE ('TO ' || pg_catalog.quote_ident(version)) LIKE '%s'"\
1096-
" AND name='%s'"
1089+
" WHERE version LIKE '%s' AND name='%s'"
10971090

10981091
#define Query_for_list_of_prepared_statements \
10991092
" SELECT name "\
@@ -1934,20 +1927,17 @@ psql_completion(const char *text, int start, int end)
19341927

19351928
/* ALTER EXTENSION <name> */
19361929
else if (Matches("ALTER", "EXTENSION", MatchAny))
1937-
COMPLETE_WITH("ADD", "DROP", "UPDATE", "SET SCHEMA");
1930+
COMPLETE_WITH("ADD", "DROP", "UPDATE TO", "SET SCHEMA");
19381931

19391932
/* ALTER EXTENSION <name> UPDATE */
19401933
else if (Matches("ALTER", "EXTENSION", MatchAny, "UPDATE"))
1941-
{
1942-
set_completion_reference(prev2_wd);
1943-
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_available_extension_versions_with_TO);
1944-
}
1934+
COMPLETE_WITH("TO");
19451935

19461936
/* ALTER EXTENSION <name> UPDATE TO */
19471937
else if (Matches("ALTER", "EXTENSION", MatchAny, "UPDATE", "TO"))
19481938
{
19491939
set_completion_reference(prev3_wd);
1950-
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_available_extension_versions);
1940+
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
19511941
}
19521942

19531943
/* ALTER FOREIGN */
@@ -2824,7 +2814,7 @@ psql_completion(const char *text, int start, int end)
28242814
else if (Matches("CREATE", "EXTENSION", MatchAny, "VERSION"))
28252815
{
28262816
set_completion_reference(prev2_wd);
2827-
COMPLETE_WITH_QUERY_VERBATIM(Query_for_list_of_available_extension_versions);
2817+
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
28282818
}
28292819

28302820
/* CREATE FOREIGN */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy