aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-06-03 11:02:32 +0900
committerMichael Paquier <michael@paquier.xyz>2019-06-03 11:02:32 +0900
commit0240a00fbd4fd14f577edf8d36a032237fd0b9cb (patch)
treebbc6df2493a2d9c14f39f64172c4158afa817d4c /src
parentf4755a2c01486519cfce5b21ab04529ad26f5ed1 (diff)
downloadpostgresql-0240a00fbd4fd14f577edf8d36a032237fd0b9cb.tar.gz
postgresql-0240a00fbd4fd14f577edf8d36a032237fd0b9cb.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/tab-complete.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index c6347b61900..5e38f463999 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -41,6 +41,7 @@
#include <ctype.h>
+#include "catalog/pg_am_d.h"
#include "catalog/pg_class_d.h"
#include "libpq-fe.h"
@@ -824,6 +825,18 @@ static const SchemaQuery Query_for_list_of_statistics = {
" FROM pg_catalog.pg_am "\
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'"
+#define Query_for_list_of_index_access_methods \
+" SELECT pg_catalog.quote_ident(amname) "\
+" FROM pg_catalog.pg_am "\
+" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
+" amtype=" CppAsString2(AMTYPE_INDEX)
+
+#define Query_for_list_of_table_access_methods \
+" SELECT pg_catalog.quote_ident(amname) "\
+" FROM pg_catalog.pg_am "\
+" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
+" amtype=" CppAsString2(AMTYPE_TABLE)
+
/* the silly-looking length condition is just to eat up the current word */
#define Query_for_list_of_arguments \
"SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
@@ -2234,7 +2247,7 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("TYPE");
/* Complete "CREATE ACCESS METHOD <name> TYPE" */
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE"))
- COMPLETE_WITH("INDEX");
+ COMPLETE_WITH("INDEX", "TABLE");
/* Complete "CREATE ACCESS METHOD <name> TYPE <type>" */
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny))
COMPLETE_WITH("HANDLER");
@@ -2322,7 +2335,7 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches("INDEX", MatchAny, MatchAny, "ON", MatchAny, "USING") ||
TailMatches("INDEX", MatchAny, "ON", MatchAny, "USING") ||
TailMatches("INDEX", "ON", MatchAny, "USING"))
- COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
+ COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods);
else if (TailMatches("ON", MatchAny, "USING", MatchAny) &&
!TailMatches("POLICY", MatchAny, MatchAny, MatchAny, MatchAny, MatchAny) &&
!TailMatches("FOR", MatchAny, MatchAny, MatchAny))
@@ -2490,10 +2503,14 @@ psql_completion(const char *text, int start, int end)
/* Complete CREATE TABLE name (...) with supported options */
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)") ||
TailMatches("CREATE", "UNLOGGED", "TABLE", MatchAny, "(*)"))
- COMPLETE_WITH("INHERITS (", "PARTITION BY", "TABLESPACE", "WITH (");
+ COMPLETE_WITH("INHERITS (", "PARTITION BY", "USING", "TABLESPACE", "WITH (");
else if (TailMatches("CREATE", "TEMP|TEMPORARY", "TABLE", MatchAny, "(*)"))
COMPLETE_WITH("INHERITS (", "ON COMMIT", "PARTITION BY",
"TABLESPACE", "WITH (");
+ /* Complete CREATE TABLE (...) USING with table access methods */
+ else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "USING") ||
+ TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "USING"))
+ COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
/* Complete CREATE TABLE (...) WITH with storage parameters */
else if (TailMatches("CREATE", "TABLE", MatchAny, "(*)", "WITH", "(") ||
TailMatches("CREATE", "TEMP|TEMPORARY|UNLOGGED", "TABLE", MatchAny, "(*)", "WITH", "("))