Skip to content

Commit 4f04b66

Browse files
committed
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
1 parent 77ba610 commit 4f04b66

File tree

9 files changed

+107
-5
lines changed

9 files changed

+107
-5
lines changed

contrib/bloom/bloom--1.0.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LANGUAGE C;
55

66
-- Access method
77
CREATE ACCESS METHOD bloom TYPE INDEX HANDLER blhandler;
8+
COMMENT ON ACCESS METHOD bloom IS 'bloom index access method';
89

910
-- Opclasses
1011

doc/src/sgml/ref/comment.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PostgreSQL documentation
2323
<synopsis>
2424
COMMENT ON
2525
{
26+
ACCESS METHOD <replaceable class="PARAMETER">object_name</replaceable> |
2627
AGGREGATE <replaceable class="PARAMETER">aggregate_name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) |
2728
CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) |
2829
COLLATION <replaceable class="PARAMETER">object_name</replaceable> |
@@ -89,6 +90,8 @@ COMMENT ON
8990
Roles don't have owners, so the rule for <literal>COMMENT ON ROLE</> is
9091
that you must be superuser to comment on a superuser role, or have the
9192
<literal>CREATEROLE</> privilege to comment on non-superuser roles.
93+
Likewise, access methods don't have owners either; you must be superuser
94+
to comment on an access method.
9295
Of course, a superuser can comment on anything.
9396
</para>
9497

@@ -296,6 +299,7 @@ COMMENT ON TABLE mytable IS NULL;
296299
Some more examples:
297300

298301
<programlisting>
302+
COMMENT ON ACCESS METHOD rtree IS 'R-Tree access method';
299303
COMMENT ON AGGREGATE my_aggregate (double precision) IS 'Computes sample variance';
300304
COMMENT ON CAST (text AS int4) IS 'Allow casts from text to int4';
301305
COMMENT ON COLLATION "fr_CA" IS 'Canadian French';

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,19 @@ testdb=&gt;
11301130
</listitem>
11311131
</varlistentry>
11321132

1133+
<varlistentry>
1134+
<term><literal>\dA[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1135+
1136+
<listitem>
1137+
<para>
1138+
Lists access methods. If <replaceable
1139+
class="parameter">pattern</replaceable> is specified, only access
1140+
methods whose names match the pattern are shown. If
1141+
<literal>+</literal> is appended to the command name, each access
1142+
method is listed with its associated handler function and description.
1143+
</para>
1144+
</listitem>
1145+
</varlistentry>
11331146

11341147
<varlistentry>
11351148
<term><literal>\db[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>

src/backend/parser/gram.y

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,7 +5693,8 @@ opt_restart_seqs:
56935693
* The COMMENT ON statement can take different forms based upon the type of
56945694
* the object associated with the comment. The form of the statement is:
56955695
*
5696-
* COMMENT ON [ [ CONVERSION | COLLATION | DATABASE | DOMAIN |
5696+
* COMMENT ON [ [ ACCESS METHOD | CONVERSION | COLLATION |
5697+
* DATABASE | DOMAIN |
56975698
* EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
56985699
* FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
56995700
* MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
@@ -5713,7 +5714,7 @@ opt_restart_seqs:
57135714
* OPERATOR FAMILY <name> USING <access-method> |
57145715
* RULE <rulename> ON <relname> |
57155716
* TRIGGER <triggername> ON <relname> ]
5716-
* IS 'text'
5717+
* IS { 'text' | NULL }
57175718
*
57185719
*****************************************************************************/
57195720

@@ -5888,7 +5889,8 @@ CommentStmt:
58885889
;
58895890

58905891
comment_type:
5891-
COLUMN { $$ = OBJECT_COLUMN; }
5892+
ACCESS METHOD { $$ = OBJECT_ACCESS_METHOD; }
5893+
| COLUMN { $$ = OBJECT_COLUMN; }
58925894
| DATABASE { $$ = OBJECT_DATABASE; }
58935895
| SCHEMA { $$ = OBJECT_SCHEMA; }
58945896
| INDEX { $$ = OBJECT_INDEX; }

src/bin/psql/command.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ exec_command(const char *cmd,
402402
/* standard listing of interesting things */
403403
success = listTables("tvmsE", NULL, show_verbose, show_system);
404404
break;
405+
case 'A':
406+
success = describeAccessMethods(pattern, show_verbose);
407+
break;
405408
case 'a':
406409
success = describeAggregates(pattern, show_verbose, show_system);
407410
break;

src/bin/psql/describe.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,70 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
129129
return true;
130130
}
131131

132+
/* \dA
133+
* Takes an optional regexp to select particular access methods
134+
*/
135+
bool
136+
describeAccessMethods(const char *pattern, bool verbose)
137+
{
138+
PQExpBufferData buf;
139+
PGresult *res;
140+
printQueryOpt myopt = pset.popt;
141+
static const bool translate_columns[] = {false, true, false};
142+
143+
if (pset.sversion < 90600)
144+
{
145+
psql_error("The server (version %d.%d) does not support access methods.\n",
146+
pset.sversion / 10000, (pset.sversion / 100) % 100);
147+
return true;
148+
}
149+
150+
initPQExpBuffer(&buf);
151+
152+
printfPQExpBuffer(&buf,
153+
"SELECT amname AS \"%s\",\n"
154+
" CASE amtype"
155+
" WHEN 'i' THEN '%s'"
156+
" END AS \"%s\"",
157+
gettext_noop("Name"),
158+
gettext_noop("Index"),
159+
gettext_noop("Type"));
160+
161+
if (verbose)
162+
{
163+
appendPQExpBuffer(&buf,
164+
",\n amhandler AS \"%s\",\n"
165+
" pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
166+
gettext_noop("Handler"),
167+
gettext_noop("Description"));
168+
}
169+
170+
appendPQExpBufferStr(&buf,
171+
"\nFROM pg_catalog.pg_am\n");
172+
173+
processSQLNamePattern(pset.db, &buf, pattern, false, false,
174+
NULL, "amname", NULL,
175+
NULL);
176+
177+
appendPQExpBufferStr(&buf, "ORDER BY 1;");
178+
179+
res = PSQLexec(buf.data);
180+
termPQExpBuffer(&buf);
181+
if (!res)
182+
return false;
183+
184+
myopt.nullPrint = NULL;
185+
myopt.title = _("List of access methods");
186+
myopt.translate_header = true;
187+
myopt.translate_columns = translate_columns;
188+
myopt.n_translate_columns = lengthof(translate_columns);
189+
190+
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
191+
192+
PQclear(res);
193+
return true;
194+
}
195+
132196
/* \db
133197
* Takes an optional regexp to select particular tablespaces
134198
*/

src/bin/psql/describe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
/* \da */
1313
extern bool describeAggregates(const char *pattern, bool verbose, bool showSystem);
1414

15+
/* \dA */
16+
extern bool describeAccessMethods(const char *pattern, bool verbose);
17+
1518
/* \db */
1619
extern bool describeTablespaces(const char *pattern, bool verbose);
1720

src/bin/psql/help.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ slashUsage(unsigned short int pager)
215215
fprintf(output, _(" \\d[S+] list tables, views, and sequences\n"));
216216
fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
217217
fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
218+
fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n"));
218219
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
219220
fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n"));
220221
fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));

src/bin/psql/tab-complete.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ psql_completion(const char *text, int start, int end)
12761276
static const char *const backslash_commands[] = {
12771277
"\\a", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy",
12781278
"\\copyright", "\\crosstabview",
1279-
"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD",
1279+
"\\d", "\\da", "\\dA", "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD",
12801280
"\\des", "\\det", "\\deu", "\\dew", "\\dE", "\\df",
12811281
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
12821282
"\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\drds", "\\ds", "\\dS",
@@ -1910,7 +1910,8 @@ psql_completion(const char *text, int start, int end)
19101910
else if (Matches2("COMMENT", "ON"))
19111911
{
19121912
static const char *const list_COMMENT[] =
1913-
{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EVENT TRIGGER", "EXTENSION",
1913+
{"ACCESS METHOD", "CAST", "COLLATION", "CONVERSION", "DATABASE",
1914+
"EVENT TRIGGER", "EXTENSION",
19141915
"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
19151916
"SERVER", "INDEX", "LANGUAGE", "POLICY", "RULE", "SCHEMA", "SEQUENCE",
19161917
"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
@@ -1919,6 +1920,8 @@ psql_completion(const char *text, int start, int end)
19191920

19201921
COMPLETE_WITH_LIST(list_COMMENT);
19211922
}
1923+
else if (Matches4("COMMENT", "ON", "ACCESS", "METHOD"))
1924+
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
19221925
else if (Matches3("COMMENT", "ON", "FOREIGN"))
19231926
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
19241927
else if (Matches4("COMMENT", "ON", "TEXT", "SEARCH"))
@@ -2331,6 +2334,12 @@ psql_completion(const char *text, int start, int end)
23312334
else if (Matches5("DROP", "TRIGGER", MatchAny, "ON", MatchAny))
23322335
COMPLETE_WITH_LIST2("CASCADE", "RESTRICT");
23332336

2337+
/* DROP ACCESS METHOD */
2338+
else if (Matches2("DROP", "ACCESS"))
2339+
COMPLETE_WITH_CONST("METHOD");
2340+
else if (Matches3("DROP", "ACCESS", "METHOD"))
2341+
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
2342+
23342343
/* DROP EVENT TRIGGER */
23352344
else if (Matches2("DROP", "EVENT"))
23362345
COMPLETE_WITH_CONST("TRIGGER");
@@ -2931,6 +2940,8 @@ psql_completion(const char *text, int start, int end)
29312940
}
29322941
else if (TailMatchesCS1("\\da*"))
29332942
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);
2943+
else if (TailMatchesCS1("\\dA*"))
2944+
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
29342945
else if (TailMatchesCS1("\\db*"))
29352946
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
29362947
else if (TailMatchesCS1("\\dD*"))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy