Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0240a00

Browse files
committed
Fix some issues and improve psql completion for access methods
The following issues have been spotted: - CREATE INDEX .. USING suggests both index and table AMs, but it should consider only index AMs. - CREATE TABLE .. USING has no completion support. USING was not being included in the completion list where it should, and follow-up suggestions for table AMs have been missing as well. - CREATE ACCESS METHOD .. TYPE suggests only INDEX, with TABLE missing. Author: Michael Paquier Discussion: https://postgr.es/m/20190601191007.GC1905@paquier.xyz
1 parent f4755a2 commit 0240a00

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/bin/psql/tab-complete.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include <ctype.h>
4343

44+
#include "catalog/pg_am_d.h"
4445
#include "catalog/pg_class_d.h"
4546

4647
#include "libpq-fe.h"
@@ -824,6 +825,18 @@ static const SchemaQuery Query_for_list_of_statistics = {
824825
" FROM pg_catalog.pg_am "\
825826
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'"
826827

828+
#define Query_for_list_of_index_access_methods \
829+
" SELECT pg_catalog.quote_ident(amname) "\
830+
" FROM pg_catalog.pg_am "\
831+
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
832+
" amtype=" CppAsString2(AMTYPE_INDEX)
833+
834+
#define Query_for_list_of_table_access_methods \
835+
" SELECT pg_catalog.quote_ident(amname) "\
836+
" FROM pg_catalog.pg_am "\
837+
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
838+
" amtype=" CppAsString2(AMTYPE_TABLE)
839+
827840
/* the silly-looking length condition is just to eat up the current word */
828841
#define Query_for_list_of_arguments \
829842
"SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
@@ -2234,7 +2247,7 @@ psql_completion(const char *text, int start, int end)
22342247
COMPLETE_WITH("TYPE");
22352248
/* Complete "CREATE ACCESS METHOD <name> TYPE" */
22362249
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE"))
2237-
COMPLETE_WITH("INDEX");
2250+
COMPLETE_WITH("INDEX", "TABLE");
22382251
/* Complete "CREATE ACCESS METHOD <name> TYPE <type>" */
22392252
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny))
22402253
COMPLETE_WITH("HANDLER");
@@ -2322,7 +2335,7 @@ psql_completion(const char *text, int start, int end)
23222335
else if (TailMatches("INDEX", MatchAny, MatchAny, "ON", MatchAny, "USING") ||
23232336
TailMatches("INDEX", MatchAny, "ON", MatchAny, "USING") ||
23242337
TailMatches("INDEX", "ON", MatchAny, "USING"))
2325-
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
2338+
COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods);
23262339
else if (TailMatches("ON", MatchAny, "USING", MatchAny) &&
23272340
!TailMatches("POLICY", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny) &&
23282341
!TailMatches("FOR", MatchAny, MatchAny, MatchAny))
@@ -2490,10 +2503,14 @@ psql_completion(const char *text, int start, int end)
24902503
/* Complete CREATE TABLE name (...) with supported options */
24912504
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") ||
24922505
TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)"))
2493-
COMPLETE_WITH("INHERITS (", "PARTITION BY", "TABLESPACE", "WITH (");
2506+
COMPLETE_WITH("INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
24942507
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)"))
24952508
COMPLETE_WITH("INHERITS (", "ON COMMIT", "PARTITION BY",
24962509
"TABLESPACE", "WITH (");
2510+
/* Complete CREATE TABLE (...) USING with table access methods */
2511+
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") ||
2512+
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "USING"))
2513+
COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
24972514
/* Complete CREATE TABLE (...) WITH with storage parameters */
24982515
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "WITH", "(") ||
24992516
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "WITH", "("))

0 commit comments

Comments
 (0)