aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2016-06-07 17:59:34 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2016-06-07 17:59:34 -0400
commit4f04b66f97f0e0265489f0fe0373ea44c9ad11bf (patch)
treeca0082bb0011ef27c5f483f5088e2eadadaea4a6 /src
parent77ba610805e7ef9ba9c9a593ea8b1ca8f98f8bcb (diff)
downloadpostgresql-4f04b66f97f0e0265489f0fe0373ea44c9ad11bf.tar.gz
postgresql-4f04b66f97f0e0265489f0fe0373ea44c9ad11bf.zip
Fix loose ends for SQL ACCESS METHOD objects
COMMENT ON ACCESS METHOD was missing; add it, along psql tab-completion support for it. psql was also missing a way to list existing access methods; the new \dA command does that. Also add tab-completion support for DROP ACCESS METHOD. Author: Michael Paquier Discussion: https://www.postgresql.org/message-id/CAB7nPqTzdZdu8J7EF8SXr_R2U5bSUUYNOT3oAWBZdEoggnwhGA@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/gram.y8
-rw-r--r--src/bin/psql/command.c3
-rw-r--r--src/bin/psql/describe.c64
-rw-r--r--src/bin/psql/describe.h3
-rw-r--r--src/bin/psql/help.c1
-rw-r--r--src/bin/psql/tab-complete.c15
6 files changed, 89 insertions, 5 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index ad338d3ddbe..2c950f937c4 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -5693,7 +5693,8 @@ opt_restart_seqs:
* The COMMENT ON statement can take different forms based upon the type of
* the object associated with the comment. The form of the statement is:
*
- * COMMENT ON [ [ CONVERSION | COLLATION | DATABASE | DOMAIN |
+ * COMMENT ON [ [ ACCESS METHOD | CONVERSION | COLLATION |
+ * DATABASE | DOMAIN |
* EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
* FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
* MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
@@ -5713,7 +5714,7 @@ opt_restart_seqs:
* OPERATOR FAMILY <name> USING <access-method> |
* RULE <rulename> ON <relname> |
* TRIGGER <triggername> ON <relname> ]
- * IS 'text'
+ * IS { 'text' | NULL }
*
*****************************************************************************/
@@ -5888,7 +5889,8 @@ CommentStmt:
;
comment_type:
- COLUMN { $$ = OBJECT_COLUMN; }
+ ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
+ | COLUMN { $$ = OBJECT_COLUMN; }
| DATABASE { $$ = OBJECT_DATABASE; }
| SCHEMA { $$ = OBJECT_SCHEMA; }
| INDEX { $$ = OBJECT_INDEX; }
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 693b5312afc..543fe5f5569 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -402,6 +402,9 @@ exec_command(const char *cmd,
/* standard listing of interesting things */
success = listTables("tvmsE", NULL, show_verbose, show_system);
break;
+ case 'A':
+ success = describeAccessMethods(pattern, show_verbose);
+ break;
case 'a':
success = describeAggregates(pattern, show_verbose, show_system);
break;
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 0a771bd2107..2a05cf95dab 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -129,6 +129,70 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
return true;
}
+/* \dA
+ * Takes an optional regexp to select particular access methods
+ */
+bool
+describeAccessMethods(const char *pattern, bool verbose)
+{
+ PQExpBufferData buf;
+ PGresult *res;
+ printQueryOpt myopt = pset.popt;
+ static const bool translate_columns[] = {false, true, false};
+
+ if (pset.sversion < 90600)
+ {
+ psql_error("The server (version %d.%d) does not support access methods.\n",
+ pset.sversion / 10000, (pset.sversion / 100) % 100);
+ return true;
+ }
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT amname AS \"%s\",\n"
+ " CASE amtype"
+ " WHEN 'i' THEN '%s'"
+ " END AS \"%s\"",
+ gettext_noop("Name"),
+ gettext_noop("Index"),
+ gettext_noop("Type"));
+
+ if (verbose)
+ {
+ appendPQExpBuffer(&buf,
+ ",\n amhandler AS \"%s\",\n"
+ " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
+ gettext_noop("Handler"),
+ gettext_noop("Description"));
+ }
+
+ appendPQExpBufferStr(&buf,
+ "\nFROM pg_catalog.pg_am\n");
+
+ processSQLNamePattern(pset.db, &buf, pattern, false, false,
+ NULL, "amname", NULL,
+ NULL);
+
+ appendPQExpBufferStr(&buf, "ORDER BY 1;");
+
+ res = PSQLexec(buf.data);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.nullPrint = NULL;
+ myopt.title = _("List of access methods");
+ myopt.translate_header = true;
+ myopt.translate_columns = translate_columns;
+ myopt.n_translate_columns = lengthof(translate_columns);
+
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
+
/* \db
* Takes an optional regexp to select particular tablespaces
*/
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 96722756b46..20a650861b6 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -12,6 +12,9 @@
/* \da */
extern bool describeAggregates(const char *pattern, bool verbose, bool showSystem);
+/* \dA */
+extern bool describeAccessMethods(const char *pattern, bool verbose);
+
/* \db */
extern bool describeTablespaces(const char *pattern, bool verbose);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index b4021417863..0d0461dc2a7 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -215,6 +215,7 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\d[S+] list tables, views, and sequences\n"));
fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
+ fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n"));
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n"));
fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index a62ffe61e05..3b07726e574 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1276,7 +1276,7 @@ psql_completion(const char *text, int start, int end)
static const char *const backslash_commands[] = {
"\\a", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy",
"\\copyright", "\\crosstabview",
- "\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD",
+ "\\d", "\\da", "\\dA", "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD",
"\\des", "\\det", "\\deu", "\\dew", "\\dE", "\\df",
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
"\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\drds", "\\ds", "\\dS",
@@ -1910,7 +1910,8 @@ psql_completion(const char *text, int start, int end)
else if (Matches2("COMMENT", "ON"))
{
static const char *const list_COMMENT[] =
- {"CAST", "COLLATION", "CONVERSION", "DATABASE", "EVENT TRIGGER", "EXTENSION",
+ {"ACCESS METHOD", "CAST", "COLLATION", "CONVERSION", "DATABASE",
+ "EVENT TRIGGER", "EXTENSION",
"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
"SERVER", "INDEX", "LANGUAGE", "POLICY", "RULE", "SCHEMA", "SEQUENCE",
"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
@@ -1919,6 +1920,8 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_COMMENT);
}
+ else if (Matches4("COMMENT", "ON", "ACCESS", "METHOD"))
+ COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
else if (Matches3("COMMENT", "ON", "FOREIGN"))
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
else if (Matches4("COMMENT", "ON", "TEXT", "SEARCH"))
@@ -2331,6 +2334,12 @@ psql_completion(const char *text, int start, int end)
else if (Matches5("DROP", "TRIGGER", MatchAny, "ON", MatchAny))
COMPLETE_WITH_LIST2("CASCADE", "RESTRICT");
+ /* DROP ACCESS METHOD */
+ else if (Matches2("DROP", "ACCESS"))
+ COMPLETE_WITH_CONST("METHOD");
+ else if (Matches3("DROP", "ACCESS", "METHOD"))
+ COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
+
/* DROP EVENT TRIGGER */
else if (Matches2("DROP", "EVENT"))
COMPLETE_WITH_CONST("TRIGGER");
@@ -2931,6 +2940,8 @@ psql_completion(const char *text, int start, int end)
}
else if (TailMatchesCS1("\\da*"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);
+ else if (TailMatchesCS1("\\dA*"))
+ COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
else if (TailMatchesCS1("\\db*"))
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
else if (TailMatchesCS1("\\dD*"))