COMMENT ON, psql and access methods

Started by Michael Paquierover 9 years ago14 messages
#1Michael Paquier
michael.paquier@gmail.com

Hi all,

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

Regards,
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#1)
Re: COMMENT ON, psql and access methods

Michael Paquier <michael.paquier@gmail.com> writes:

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

I'm a bit skeptical that we need this yet. Maybe if custom access methods
become so popular that everybody's got one, it'd be worth the trouble.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#1)
Re: COMMENT ON, psql and access methods

On Fri, May 27, 2016 at 7:53 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

+1.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#3)
Re: COMMENT ON, psql and access methods

On Wed, Jun 1, 2016 at 4:52 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Fri, May 27, 2016 at 7:53 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

+1.

Are there other opinions? That's not a 9.6 blocker IMO, so I could get
patches out for 10.0 if needed.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Teodor Sigaev
teodor@sigaev.ru
In reply to: Michael Paquier (#4)
Re: COMMENT ON, psql and access methods

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

+1.

Are there other opinions? That's not a 9.6 blocker IMO, so I could get
patches out for 10.0 if needed.

I missed that on review process, but I'm agree it should be implemented.

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Michael Paquier
michael.paquier@gmail.com
In reply to: Teodor Sigaev (#5)
1 attachment(s)
Re: COMMENT ON, psql and access methods

On Wed, Jun 1, 2016 at 8:25 PM, Teodor Sigaev <teodor@sigaev.ru> wrote:

As far as I can see, COMMENT ON has no support for access methods.
Wouldn't we want to add it as it is created by a command? On top of
that, perhaps we could have a backslash command in psql to list the
supported access methods, like \dam[S]? The system methods would be in
this case all the in-core ones.

+1.

Are there other opinions? That's not a 9.6 blocker IMO, so I could get
patches out for 10.0 if needed.

I missed that on review process, but I'm agree it should be implemented.

So, I have taken the time to hack that, and finished with the patch
attached, that is less intrusive than I thought first:
- COMMENT support is added for access methods
- Added meta-command \dA in psql to list the available access methods:
=# \dA
List of access methods
Name | Type
--------+-------
bloom | Index
brin | Index
btree | Index
gin | Index
gist | Index
hash | Index
spgist | Index
(7 rows)
=# \dA+
List of access methods
Name | Type | Handler | Description
--------+-------+-------------+----------------------------------------
bloom | Index | blhandler | bloom index access method
brin | Index | brinhandler | block range index (BRIN) access method
btree | Index | bthandler | b-tree index access method
gin | Index | ginhandler | GIN index access method
gist | Index | gisthandler | GiST index access method
hash | Index | hashhandler | hash index access method
spgist | Index | spghandler | SP-GiST index access method
(7 rows)
- Fixed a missing tab completion for DROP ACCESS METHOD.

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.
Regards,
--
Michael

Attachments:

0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchtext/x-diff; charset=US-ASCII; name=0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchDownload
From 12c5d77c7d66cd8b33c697fc389cf9915d32765b Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Thu, 2 Jun 2016 12:47:46 +0900
Subject: [PATCH] Add support for COMMENT ON and psql meta-command for access
 methods

473b932 has visibly forgotten that access methods, being database objects
could have a description associated with them. Having a psql-level meta
command that allows to list all the access commands available on the
server was missing as well.

At the same time, I have noticed that tab completion of psql could be
more verbose regarding access methods, those things are fixed at the
same time.
---
 contrib/bloom/bloom--1.0.sql   |  1 +
 doc/src/sgml/ref/comment.sgml  |  1 +
 doc/src/sgml/ref/psql-ref.sgml | 13 +++++++++
 src/backend/parser/gram.y      |  5 ++--
 src/bin/psql/command.c         |  3 +++
 src/bin/psql/describe.c        | 61 ++++++++++++++++++++++++++++++++++++++++++
 src/bin/psql/describe.h        |  3 +++
 src/bin/psql/tab-complete.c    | 30 ++++++++++++++++-----
 8 files changed, 108 insertions(+), 9 deletions(-)

diff --git a/contrib/bloom/bloom--1.0.sql b/contrib/bloom/bloom--1.0.sql
index 7fa7513..87b5442 100644
--- a/contrib/bloom/bloom--1.0.sql
+++ b/contrib/bloom/bloom--1.0.sql
@@ -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
 
diff --git a/doc/src/sgml/ref/comment.sgml b/doc/src/sgml/ref/comment.sgml
index 3321d4b..9582de8 100644
--- a/doc/src/sgml/ref/comment.sgml
+++ b/doc/src/sgml/ref/comment.sgml
@@ -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> |
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index df79a37..4079ac6 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -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>
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 20384db..5d646e7 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -5693,8 +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 |
- *                 EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
+ *	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 |
  *                 SERVER | TABLE | TABLESPACE |
@@ -5896,6 +5896,7 @@ comment_type:
 			| TABLE								{ $$ = OBJECT_TABLE; }
 			| VIEW								{ $$ = OBJECT_VIEW; }
 			| MATERIALIZED VIEW					{ $$ = OBJECT_MATVIEW; }
+			| ACCESS METHOD						{ $$ = OBJECT_ACCESS_METHOD; }
 			| COLLATION							{ $$ = OBJECT_COLLATION; }
 			| CONVERSION_P						{ $$ = OBJECT_CONVERSION; }
 			| TABLESPACE						{ $$ = OBJECT_TABLESPACE; }
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 693b531..543fe5f 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 0a771bd..4e9e6ac 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -129,6 +129,67 @@ 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;
+
+	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;
+
+	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 9672275..20a6508 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/tab-complete.c b/src/bin/psql/tab-complete.c
index a62ffe6..7cc4090 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -830,6 +830,11 @@ static const SchemaQuery Query_for_list_of_matviews = {
 "   FROM pg_catalog.pg_event_trigger "\
 "  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
 
+#define Query__for_list_of_access_methods \
+" SELECT pg_catalog.quote_ident(amname) "\
+"   FROM pg_catalog.pg_am "\
+"  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
+
 #define Query_for_list_of_tablesample_methods \
 " SELECT pg_catalog.quote_ident(proname) "\
 "   FROM pg_catalog.pg_proc "\
@@ -1276,7 +1281,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,15 +1915,18 @@ 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",
-			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
-			"SERVER", "INDEX", "LANGUAGE", "POLICY", "RULE", "SCHEMA", "SEQUENCE",
-			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
-			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
-		"TABLESPACE", "TEXT SEARCH", "ROLE", NULL};
+			{"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", "OPERATOR", "TRIGGER",
+			"CONSTRAINT", "DOMAIN", "LARGE OBJECT", "TABLESPACE",
+			"TEXT SEARCH", "ROLE", NULL};
 
 		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 +2339,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 +2945,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*"))
-- 
2.8.3

#7Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#6)
1 attachment(s)
Re: COMMENT ON, psql and access methods

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.
--
Michael

Attachments:

0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchtext/x-patch; charset=US-ASCII; name=0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchDownload
From 9901595fd000c3ac9e1c1ce8ee2f21218c4803c7 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Thu, 2 Jun 2016 12:47:46 +0900
Subject: [PATCH] Add support for COMMENT ON and psql meta-command for access
 methods

473b932 has visibly forgotten that access methods, being database objects
could have a description associated with them. Having a psql-level meta
command that allows to list all the access commands available on the
server was missing as well.

At the same time, I have noticed that tab completion of psql could be
more verbose regarding access methods, those things are fixed at the
same time.
---
 contrib/bloom/bloom--1.0.sql   |  1 +
 doc/src/sgml/ref/comment.sgml  |  1 +
 doc/src/sgml/ref/psql-ref.sgml | 13 +++++++++
 src/backend/parser/gram.y      |  5 ++--
 src/bin/psql/command.c         |  3 +++
 src/bin/psql/describe.c        | 61 ++++++++++++++++++++++++++++++++++++++++++
 src/bin/psql/describe.h        |  3 +++
 src/bin/psql/help.c            |  1 +
 src/bin/psql/tab-complete.c    | 30 ++++++++++++++++-----
 9 files changed, 109 insertions(+), 9 deletions(-)

diff --git a/contrib/bloom/bloom--1.0.sql b/contrib/bloom/bloom--1.0.sql
index 7fa7513..87b5442 100644
--- a/contrib/bloom/bloom--1.0.sql
+++ b/contrib/bloom/bloom--1.0.sql
@@ -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
 
diff --git a/doc/src/sgml/ref/comment.sgml b/doc/src/sgml/ref/comment.sgml
index 3321d4b..9582de8 100644
--- a/doc/src/sgml/ref/comment.sgml
+++ b/doc/src/sgml/ref/comment.sgml
@@ -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> |
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index df79a37..4079ac6 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -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>
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 20384db..5d646e7 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -5693,8 +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 |
- *                 EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
+ *	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 |
  *                 SERVER | TABLE | TABLESPACE |
@@ -5896,6 +5896,7 @@ comment_type:
 			| TABLE								{ $$ = OBJECT_TABLE; }
 			| VIEW								{ $$ = OBJECT_VIEW; }
 			| MATERIALIZED VIEW					{ $$ = OBJECT_MATVIEW; }
+			| ACCESS METHOD						{ $$ = OBJECT_ACCESS_METHOD; }
 			| COLLATION							{ $$ = OBJECT_COLLATION; }
 			| CONVERSION_P						{ $$ = OBJECT_CONVERSION; }
 			| TABLESPACE						{ $$ = OBJECT_TABLESPACE; }
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 693b531..543fe5f 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 0a771bd..4e9e6ac 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -129,6 +129,67 @@ 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;
+
+	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;
+
+	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 9672275..20a6508 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 b402141..0d0461d 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 a62ffe6..7cc4090 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -830,6 +830,11 @@ static const SchemaQuery Query_for_list_of_matviews = {
 "   FROM pg_catalog.pg_event_trigger "\
 "  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
 
+#define Query__for_list_of_access_methods \
+" SELECT pg_catalog.quote_ident(amname) "\
+"   FROM pg_catalog.pg_am "\
+"  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
+
 #define Query_for_list_of_tablesample_methods \
 " SELECT pg_catalog.quote_ident(proname) "\
 "   FROM pg_catalog.pg_proc "\
@@ -1276,7 +1281,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,15 +1915,18 @@ 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",
-			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
-			"SERVER", "INDEX", "LANGUAGE", "POLICY", "RULE", "SCHEMA", "SEQUENCE",
-			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
-			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
-		"TABLESPACE", "TEXT SEARCH", "ROLE", NULL};
+			{"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", "OPERATOR", "TRIGGER",
+			"CONSTRAINT", "DOMAIN", "LARGE OBJECT", "TABLESPACE",
+			"TEXT SEARCH", "ROLE", NULL};
 
 		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 +2339,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 +2945,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*"))
-- 
2.8.3

#8Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#7)
1 attachment(s)
Re: COMMENT ON, psql and access methods

On Thu, Jun 2, 2016 at 3:42 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.

And Query_for_list_of_access_methods was defined more or less twice,
the one of my patch having an error...
--
Michael

Attachments:

0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchtext/x-patch; charset=US-ASCII; name=0001-Add-support-for-COMMENT-ON-and-psql-meta-command-for.patchDownload
From 220cb52ecde2943ce909a3a418c3b6e1e5171863 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Thu, 2 Jun 2016 15:59:31 +0900
Subject: [PATCH] Add support for COMMENT ON and psql meta-command for access 
 methods

473b932 has visibly forgotten that access methods, being database objects
could have a description associated with them. Having a psql-level meta
command that allows to list all the access commands available on the
server was missing as well.

At the same time, I have noticed that tab completion of psql could be
more verbose regarding access methods, those things are fixed at the
same time.
---
 contrib/bloom/bloom--1.0.sql   |  1 +
 doc/src/sgml/ref/comment.sgml  |  1 +
 doc/src/sgml/ref/psql-ref.sgml | 13 +++++++++
 src/backend/parser/gram.y      |  5 ++--
 src/bin/psql/command.c         |  3 +++
 src/bin/psql/describe.c        | 61 ++++++++++++++++++++++++++++++++++++++++++
 src/bin/psql/describe.h        |  3 +++
 src/bin/psql/help.c            |  1 +
 src/bin/psql/tab-complete.c    | 25 ++++++++++++-----
 9 files changed, 104 insertions(+), 9 deletions(-)

diff --git a/contrib/bloom/bloom--1.0.sql b/contrib/bloom/bloom--1.0.sql
index 7fa7513..87b5442 100644
--- a/contrib/bloom/bloom--1.0.sql
+++ b/contrib/bloom/bloom--1.0.sql
@@ -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
 
diff --git a/doc/src/sgml/ref/comment.sgml b/doc/src/sgml/ref/comment.sgml
index 3321d4b..9582de8 100644
--- a/doc/src/sgml/ref/comment.sgml
+++ b/doc/src/sgml/ref/comment.sgml
@@ -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> |
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index df79a37..4079ac6 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -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>
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 20384db..5d646e7 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -5693,8 +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 |
- *                 EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
+ *	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 |
  *                 SERVER | TABLE | TABLESPACE |
@@ -5896,6 +5896,7 @@ comment_type:
 			| TABLE								{ $$ = OBJECT_TABLE; }
 			| VIEW								{ $$ = OBJECT_VIEW; }
 			| MATERIALIZED VIEW					{ $$ = OBJECT_MATVIEW; }
+			| ACCESS METHOD						{ $$ = OBJECT_ACCESS_METHOD; }
 			| COLLATION							{ $$ = OBJECT_COLLATION; }
 			| CONVERSION_P						{ $$ = OBJECT_CONVERSION; }
 			| TABLESPACE						{ $$ = OBJECT_TABLESPACE; }
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 693b531..543fe5f 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 0a771bd..4e9e6ac 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -129,6 +129,67 @@ 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;
+
+	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;
+
+	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 9672275..20a6508 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 b402141..0d0461d 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 a62ffe6..f4a83ca 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,15 +1910,18 @@ 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",
-			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
-			"SERVER", "INDEX", "LANGUAGE", "POLICY", "RULE", "SCHEMA", "SEQUENCE",
-			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
-			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
-		"TABLESPACE", "TEXT SEARCH", "ROLE", NULL};
+			{"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", "OPERATOR", "TRIGGER",
+			"CONSTRAINT", "DOMAIN", "LARGE OBJECT", "TABLESPACE",
+			"TEXT SEARCH", "ROLE", NULL};
 
 		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*"))
-- 
2.8.3

#9Noah Misch
noah@leadboat.com
In reply to: Michael Paquier (#8)
Re: COMMENT ON, psql and access methods

On Thu, Jun 02, 2016 at 04:00:33PM +0900, Michael Paquier wrote:

On Thu, Jun 2, 2016 at 3:42 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.

And Query_for_list_of_access_methods was defined more or less twice,
the one of my patch having an error...

[Action required within 72 hours. This is a generic notification.]

The above-described topic is currently a PostgreSQL 9.6 open item. �lvaro,
since you committed the patch believed to have created it, you own this open
item. If some other commit is more relevant or if this does not belong as a
9.6 open item, please let us know. Otherwise, please observe the policy on
open item ownership[1]/messages/by-id/20160527025039.GA447393@tornado.leadboat.com and send a status update within 72 hours of this
message. Include a date for your subsequent status update. Testers may
discover new open items at any time, and I want to plan to get them all fixed
well in advance of shipping 9.6rc1. Consequently, I will appreciate your
efforts toward speedy resolution. Thanks.

[1]: /messages/by-id/20160527025039.GA447393@tornado.leadboat.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Noah Misch (#9)
Re: COMMENT ON, psql and access methods

Noah Misch wrote:

The above-described topic is currently a PostgreSQL 9.6 open item. �lvaro,
since you committed the patch believed to have created it, you own this open
item. If some other commit is more relevant or if this does not belong as a
9.6 open item, please let us know. Otherwise, please observe the policy on
open item ownership[1] and send a status update within 72 hours of this
message. Include a date for your subsequent status update. Testers may
discover new open items at any time, and I want to plan to get them all fixed
well in advance of shipping 9.6rc1. Consequently, I will appreciate your
efforts toward speedy resolution. Thanks.

I'll have this patch reviewed, and barring serious problems, committed
no later than EOB Friday 10th.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#8)
Re: COMMENT ON, psql and access methods

Michael Paquier wrote:

On Thu, Jun 2, 2016 at 3:42 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.

And Query_for_list_of_access_methods was defined more or less twice,
the one of my patch having an error...

In looking at the DROP ACCESS METHOD completion I noticed that the
words_after_create gadget is a bit buggy: for things with more than one
word in the thing name (such as MATERIALIZED VIEW, USER MAPPING FOR,
EVENT TRIGGER among others) the "query/squery"-based completion isn't
triggered, because the loop at the end of psql_completion only considers
a single word (using strcmp against prev_wd), which obviously doesn't
match the multiple-word specifier in the struct. Some things such as
EVENT TRIGGER and MATERIALIZED VIEW have specialized code that does the
actual work; the latter specifies a query in words_after_create, but
it's dead code. As a probably separate but related bug, CREATE USER
MAPPING FOR stops working after you tab-complete the USER in it.
Lastly, there is an entry for CONFIGURATION which also doesn't work: if
you enter "DROP <tab>" it doesn't complete CONFIGURATION, but if you
enter "DROP CONFIGURATION <tab>" then it shows a list of text search
configurations, which is not a valid command.

To conclude, so far as I can tell, your patch (for DROP AM completion)
is fine, but the existing code has some minor flags which we could just
as well ignore for now, but could be improved in the future.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Michael Paquier
michael.paquier@gmail.com
In reply to: Alvaro Herrera (#11)
Re: COMMENT ON, psql and access methods

On Tue, Jun 7, 2016 at 7:35 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

In looking at the DROP ACCESS METHOD completion I noticed that the
words_after_create gadget is a bit buggy: for things with more than one
word in the thing name (such as MATERIALIZED VIEW, USER MAPPING FOR,
EVENT TRIGGER among others) the "query/squery"-based completion isn't
triggered, because the loop at the end of psql_completion only considers
a single word (using strcmp against prev_wd), which obviously doesn't
match the multiple-word specifier in the struct. Some things such as
EVENT TRIGGER and MATERIALIZED VIEW have specialized code that does the
actual work; the latter specifies a query in words_after_create, but
it's dead code. As a probably separate but related bug, CREATE USER
MAPPING FOR stops working after you tab-complete the USER in it.

Yes, that's not new...

Lastly, there is an entry for CONFIGURATION which also doesn't work:
if you enter "DROP <tab>" it doesn't complete CONFIGURATION, but if you
enter "DROP CONFIGURATION <tab>" then it shows a list of text search
configurations, which is not a valid command.

This is not a new issue as well. Even before the tab completion
refactoring things are behaving this way. There is much room for
improvements. The refactoring makes back-patching a bit more
difficult, so we may just want to get those improvements in 9.6~ based
on the lack of complaints regarding that.

To conclude, so far as I can tell, your patch (for DROP AM completion)
is fine, but the existing code has some minor flags which we could just
as well ignore for now, but could be improved in the future.

Thanks!
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#8)
Re: COMMENT ON, psql and access methods

Michael Paquier wrote:

On Thu, Jun 2, 2016 at 3:42 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.

And Query_for_list_of_access_methods was defined more or less twice,
the one of my patch having an error...

Thanks, I have pushed this. I only added a "translate_columns" option
to printQuery.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14Michael Paquier
michael.paquier@gmail.com
In reply to: Alvaro Herrera (#13)
Re: COMMENT ON, psql and access methods

On Wed, Jun 8, 2016 at 7:06 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Michael Paquier wrote:

On Thu, Jun 2, 2016 at 3:42 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Jun 2, 2016 at 1:00 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I have added an open item for 9.6 regarding this patch, that would be
good to complete this work in this release for consistency with the
other objects.

Doh. I forgot to update psql --help.

And Query_for_list_of_access_methods was defined more or less twice,
the one of my patch having an error...

Thanks, I have pushed this. I only added a "translate_columns" option
to printQuery.

Thanks.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers