1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Fix minor issues in psql's new \dAc and related commands.

The type-name pattern in \dAc and \dAf was matched only to the actual
pg_type.typname string, which is fairly user-unfriendly in cases where
that is not what's shown to the user by format_type (compare "_int4"
and "integer[]").  Make this code match what \dT does, i.e. match the
pattern against either typname or format_type() output.  Also fix its
broken handling of schema-name restrictions.  (IOW, make these
processSQLNamePattern calls match \dT's.)  While here, adjust
whitespace to make the query a little prettier in -E output, too.

Also improve some inaccuracies and shaky grammar in the related
documentation.

Noted while working on a patch for intarray's opclasses; I wondered
why I couldn't get a match to "integer*" for the input type name.
This commit is contained in:
Tom Lane
2020-08-02 17:00:26 -04:00
parent 6ee3b5fb99
commit 533020d050
3 changed files with 48 additions and 27 deletions

View File

@ -6056,7 +6056,7 @@ printACLColumn(PQExpBuffer buf, const char *colname)
* \dAc
* Lists operator classes
*
* Takes an optional regexps to filter by index access method and type.
* Takes optional regexps to filter by index access method and input data type.
*/
bool
listOperatorClasses(const char *access_method_pattern,
@ -6110,6 +6110,7 @@ listOperatorClasses(const char *access_method_pattern,
" LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
" LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
" LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
);
if (verbose)
appendPQExpBuffer(&buf,
@ -6120,8 +6121,13 @@ listOperatorClasses(const char *access_method_pattern,
have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
false, false, NULL, "am.amname", NULL, NULL);
if (type_pattern)
{
/* Match type name pattern against either internal or external name */
processSQLNamePattern(pset.db, &buf, type_pattern, have_where, false,
NULL, "t.typname", NULL, NULL);
"tn.nspname", "t.typname",
"pg_catalog.format_type(t.oid, NULL)",
"pg_catalog.pg_type_is_visible(t.oid)");
}
appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
res = PSQLexec(buf.data);
@ -6145,7 +6151,7 @@ listOperatorClasses(const char *access_method_pattern,
* \dAf
* Lists operator families
*
* Takes an optional regexps to filter by index access method and type.
* Takes optional regexps to filter by index access method and input data type.
*/
bool
listOperatorFamilies(const char *access_method_pattern,
@ -6190,15 +6196,19 @@ listOperatorFamilies(const char *access_method_pattern,
if (type_pattern)
{
appendPQExpBuffer(&buf,
"\n %s EXISTS (\n"
" %s EXISTS (\n"
" SELECT 1\n"
" FROM pg_catalog.pg_type t\n"
" JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
" WHERE oc.opcfamily = f.oid",
" LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
" WHERE oc.opcfamily = f.oid\n",
have_where ? "AND" : "WHERE");
/* Match type name pattern against either internal or external name */
processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
NULL, "t.typname", NULL, NULL);
appendPQExpBuffer(&buf, ")");
"tn.nspname", "t.typname",
"pg_catalog.format_type(t.oid, NULL)",
"pg_catalog.pg_type_is_visible(t.oid)");
appendPQExpBuffer(&buf, " )\n");
}
appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
@ -6223,7 +6233,7 @@ listOperatorFamilies(const char *access_method_pattern,
* \dAo
* Lists operators of operator families
*
* Takes an optional regexps to filter by index access method and operator
* Takes optional regexps to filter by index access method and operator
* family.
*/
bool
@ -6310,7 +6320,7 @@ listOpFamilyOperators(const char *access_method_pattern,
* \dAp
* Lists support functions of operator families
*
* Takes an optional regexps to filter by index access method and operator
* Takes optional regexps to filter by index access method and operator
* family.
*/
bool