]> granicus.if.org Git - postgresql/commitdiff
Fix loose ends for SQL ACCESS METHOD objects
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 7 Jun 2016 21:59:34 +0000 (17:59 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 7 Jun 2016 21:59:34 +0000 (17:59 -0400)
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

contrib/bloom/bloom--1.0.sql
doc/src/sgml/ref/comment.sgml
doc/src/sgml/ref/psql-ref.sgml
src/backend/parser/gram.y
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h
src/bin/psql/help.c
src/bin/psql/tab-complete.c

index 7fa751361aa81b9fc639520541bf2838cf6c1c0b..87b5442568191b48993de3264a7dc01015c30cdf 100644 (file)
@@ -5,6 +5,7 @@ LANGUAGE C;
 
 -- Access method
 CREATE ACCESS METHOD bloom TYPE INDEX HANDLER blhandler;
+COMMENT ON ACCESS METHOD bloom IS 'bloom index access method';
 
 -- Opclasses
 
index 3321d4b49d67929450032f468ee4be9d5ed5874f..fdebbffc70581b0fafc5e61bdf4b4122c0daffa0 100644 (file)
@@ -23,6 +23,7 @@ PostgreSQL documentation
 <synopsis>
 COMMENT ON
 {
+  ACCESS METHOD <replaceable class="PARAMETER">object_name</replaceable> |
   AGGREGATE <replaceable class="PARAMETER">aggregate_name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) |
   CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) |
   COLLATION <replaceable class="PARAMETER">object_name</replaceable> |
@@ -89,6 +90,8 @@ COMMENT ON
    Roles don't have owners, so the rule for <literal>COMMENT ON ROLE</> is
    that you must be superuser to comment on a superuser role, or have the
    <literal>CREATEROLE</> privilege to comment on non-superuser roles.
+   Likewise, access methods don't have owners either; you must be superuser
+   to comment on an access method.
    Of course, a superuser can comment on anything.
   </para>
 
@@ -296,6 +299,7 @@ COMMENT ON TABLE mytable IS NULL;
    Some more examples:
 
 <programlisting>
+COMMENT ON ACCESS METHOD rtree IS 'R-Tree access method';
 COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance';
 COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
 COMMENT ON COLLATION "fr_CA" IS 'Canadian French';
index 06803ab89ca08e3f1021e5c1021ee9ffc1f38aca..aef72284d26de081563c2515999d20589d17ca37 100644 (file)
@@ -1130,6 +1130,19 @@ testdb=&gt;
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><literal>\dA[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+
+        <listitem>
+        <para>
+        Lists access methods. If <replaceable
+        class="parameter">pattern</replaceable> is specified, only access
+        methods whose names match the pattern are shown. If
+        <literal>+</literal> is appended to the command name, each access
+        method is listed with its associated handler function and description.
+        </para>
+        </listitem>
+      </varlistentry>
 
       <varlistentry>
         <term><literal>\db[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
index ad338d3ddbe0f039fc2a4f83ffc0121fc64cffb7..2c950f937c49a1513867c590592ba412726c023f 100644 (file)
@@ -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; }
index 693b5312afc1395afe936645e7ae894089c79263..543fe5f5569a1895b0bb01615116332b49094471 100644 (file)
@@ -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;
index 0a771bd2107fd41336a1148c06ff772c35f84dca..2a05cf95dabfb601b75641f19305d313d3521624 100644 (file)
@@ -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
  */
index 96722756b46dcb2bacf9353f336e5a2f434d1197..20a650861b6426ce117b4c7f8c76f42c2ab778db 100644 (file)
@@ -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);
 
index b4021417863625e3b71eaf012e5c9eb5d77d3e6d..0d0461dc2a7e15db6bfa5b8b8d4d8fd8c0397eec 100644 (file)
@@ -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"));
index a62ffe61e051cabda6fb60b449812163194a90b6..3b07726e5747703599f0405c489df5b58e40522c 100644 (file)
@@ -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*"))