Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ae29005

Browse files
committed
Improvements to psql \dAo and \dAp commands
* Strategy number and purpose are essential information for opfamily operator. So, show those columns in non-verbose output. * "Left/right arg type" \dAp column names are confusing, because those type don't necessary match to function arguments. Rename them to "Registered left/right type". * Replace manual assembling of operator/procedure names with casts to regoperator/regprocedure. * Add schema-qualification for pg_catalog functions and tables. Reported-by: Peter Eisentraut, Tom Lane Reviewed-by: Tom Lane Discussion: https://postgr.es/m/2edc7b27-031f-b2b6-0db2-864241c91cb9%402ndquadrant.com Backpatch-through: 13
1 parent d8a7ce2 commit ae29005

File tree

5 files changed

+98
-99
lines changed

5 files changed

+98
-99
lines changed

src/bin/psql/command.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
747747
success = listOpFamilyOperators(pattern, pattern2, show_verbose);
748748
break;
749749
case 'p':
750-
success = listOpFamilyFunctions(pattern, pattern2);
750+
success = listOpFamilyFunctions(pattern, pattern2, show_verbose);
751751
break;
752752
default:
753753
status = PSQL_CMD_UNKNOWN;

src/bin/psql/describe.c

+46-47
Original file line numberDiff line numberDiff line change
@@ -6067,15 +6067,16 @@ listOperatorClasses(const char *access_method_pattern,
60676067
printfPQExpBuffer(&buf,
60686068
"SELECT DISTINCT"
60696069
" am.amname AS \"%s\",\n"
6070-
" c.opcintype::pg_catalog.regtype AS \"%s\",\n"
6071-
" (CASE WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6072-
" THEN c.opckeytype\n"
6073-
" ELSE NULL -- c.opcintype\n"
6074-
" END)::pg_catalog.regtype AS \"%s\",\n"
6070+
" pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6071+
" CASE\n"
6072+
" WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6073+
" THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6074+
" ELSE NULL\n"
6075+
" END AS \"%s\",\n"
60756076
" CASE\n"
60766077
" WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6077-
" THEN format('%%I', c.opcname)\n"
6078-
" ELSE format('%%I.%%I', n.nspname, c.opcname)\n"
6078+
" THEN pg_catalog.format('%%I', c.opcname)\n"
6079+
" ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
60796080
" END AS \"%s\",\n"
60806081
" (CASE WHEN c.opcdefault\n"
60816082
" THEN '%s'\n"
@@ -6092,8 +6093,8 @@ listOperatorClasses(const char *access_method_pattern,
60926093
appendPQExpBuffer(&buf,
60936094
",\n CASE\n"
60946095
" WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6095-
" THEN format('%%I', of.opfname)\n"
6096-
" ELSE format('%%I.%%I', ofn.nspname, of.opfname)\n"
6096+
" THEN pg_catalog.format('%%I', of.opfname)\n"
6097+
" ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
60976098
" END AS \"%s\",\n"
60986099
" pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
60996100
gettext_noop("Operator family"),
@@ -6157,12 +6158,12 @@ listOperatorFamilies(const char *access_method_pattern,
61576158
" am.amname AS \"%s\",\n"
61586159
" CASE\n"
61596160
" WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6160-
" THEN format('%%I', f.opfname)\n"
6161-
" ELSE format('%%I.%%I', n.nspname, f.opfname)\n"
6161+
" THEN pg_catalog.format('%%I', f.opfname)\n"
6162+
" ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
61626163
" END AS \"%s\",\n"
61636164
" (SELECT\n"
6164-
" string_agg(format_type(oc.opcintype, -1), ', ')\n"
6165-
" FROM pg_opclass oc\n"
6165+
" pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
6166+
" FROM pg_catalog.pg_opclass oc\n"
61666167
" WHERE oc.opcfamily = f.oid) \"%s\"",
61676168
gettext_noop("AM"),
61686169
gettext_noop("Operator family"),
@@ -6185,8 +6186,8 @@ listOperatorFamilies(const char *access_method_pattern,
61856186
appendPQExpBuffer(&buf,
61866187
"\n %s EXISTS (\n"
61876188
" SELECT 1\n"
6188-
" FROM pg_type t\n"
6189-
" JOIN pg_opclass oc ON oc.opcintype = t.oid\n"
6189+
" FROM pg_catalog.pg_type t\n"
6190+
" JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
61906191
" WHERE oc.opcfamily = f.oid",
61916192
have_where ? "AND" : "WHERE");
61926193
processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
@@ -6237,38 +6238,29 @@ listOpFamilyOperators(const char *access_method_pattern,
62376238
" am.amname AS \"%s\",\n"
62386239
" CASE\n"
62396240
" WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6240-
" THEN format('%%I', of.opfname)\n"
6241-
" ELSE format('%%I.%%I', nsf.nspname, of.opfname)\n"
6241+
" THEN pg_catalog.format('%%I', of.opfname)\n"
6242+
" ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
62426243
" END AS \"%s\",\n"
6243-
" format ('%%s (%%s, %%s)',\n"
6244-
" CASE\n"
6245-
" WHEN pg_catalog.pg_operator_is_visible(op.oid) \n"
6246-
" THEN op.oprname::pg_catalog.text \n"
6247-
" ELSE o.amopopr::pg_catalog.regoper::pg_catalog.text \n"
6248-
" END,\n"
6249-
" pg_catalog.format_type(o.amoplefttype, NULL),\n"
6250-
" pg_catalog.format_type(o.amoprighttype, NULL)\n"
6251-
" ) AS \"%s\"\n",
6244+
" o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
6245+
" o.amopstrategy AS \"%s\",\n"
6246+
" CASE o.amoppurpose\n"
6247+
" WHEN 'o' THEN '%s'\n"
6248+
" WHEN 's' THEN '%s'\n"
6249+
" END AS \"%s\"\n",
62526250
gettext_noop("AM"),
62536251
gettext_noop("Operator family"),
6254-
gettext_noop("Operator"));
6252+
gettext_noop("Operator"),
6253+
gettext_noop("Strategy"),
6254+
gettext_noop("ordering"),
6255+
gettext_noop("search"),
6256+
gettext_noop("Purpose"));
62556257

62566258
if (verbose)
62576259
appendPQExpBuffer(&buf,
6258-
", o.amopstrategy AS \"%s\",\n"
6259-
" CASE o.amoppurpose\n"
6260-
" WHEN 'o' THEN '%s'\n"
6261-
" WHEN 's' THEN '%s'\n"
6262-
" END AS \"%s\",\n"
6263-
" ofs.opfname AS \"%s\"\n",
6264-
gettext_noop("Strategy"),
6265-
gettext_noop("ordering"),
6266-
gettext_noop("search"),
6267-
gettext_noop("Purpose"),
6260+
", ofs.opfname AS \"%s\"\n",
62686261
gettext_noop("Sort opfamily"));
62696262
appendPQExpBuffer(&buf,
62706263
"FROM pg_catalog.pg_amop o\n"
6271-
" LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
62726264
" LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
62736265
" LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
62746266
" LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
@@ -6317,7 +6309,7 @@ listOpFamilyOperators(const char *access_method_pattern,
63176309
*/
63186310
bool
63196311
listOpFamilyFunctions(const char *access_method_pattern,
6320-
const char *family_pattern)
6312+
const char *family_pattern, bool verbose)
63216313
{
63226314
PQExpBufferData buf;
63236315
PGresult *res;
@@ -6332,19 +6324,26 @@ listOpFamilyFunctions(const char *access_method_pattern,
63326324
" am.amname AS \"%s\",\n"
63336325
" CASE\n"
63346326
" WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6335-
" THEN format('%%I', of.opfname)\n"
6336-
" ELSE format('%%I.%%I', ns.nspname, of.opfname)\n"
6327+
" THEN pg_catalog.format('%%I', of.opfname)\n"
6328+
" ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
63376329
" END AS \"%s\",\n"
63386330
" pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
63396331
" pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
6340-
" ap.amprocnum AS \"%s\"\n,"
6341-
" p.proname AS \"%s\"\n",
6332+
" ap.amprocnum AS \"%s\"\n",
63426333
gettext_noop("AM"),
63436334
gettext_noop("Operator family"),
6344-
gettext_noop("Left arg type"),
6345-
gettext_noop("Right arg type"),
6346-
gettext_noop("Number"),
6347-
gettext_noop("Function"));
6335+
gettext_noop("Registered left type"),
6336+
gettext_noop("Registered right type"),
6337+
gettext_noop("Number"));
6338+
6339+
if (!verbose)
6340+
appendPQExpBuffer(&buf,
6341+
", p.proname AS \"%s\"\n",
6342+
gettext_noop("Function"));
6343+
else
6344+
appendPQExpBuffer(&buf,
6345+
", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
6346+
gettext_noop("Function"));
63486347

63496348
appendPQExpBuffer(&buf,
63506349
"FROM pg_catalog.pg_amproc ap\n"

src/bin/psql/describe.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ extern bool listOpFamilyOperators(const char *accessMethod_pattern,
130130

131131
/* \dAp */
132132
extern bool listOpFamilyFunctions(const char *access_method_pattern,
133-
const char *family_pattern);
133+
const char *family_pattern, bool verbose);
134134

135135

136136
#endif /* DESCRIBE_H */

src/test/regress/expected/psql.out

+49-49
Original file line numberDiff line numberDiff line change
@@ -4953,62 +4953,62 @@ List of access methods
49534953
(1 row)
49544954

49554955
\dAo+ btree float_ops
4956-
List of operators of operator families
4957-
AM | Operator family | Operator | Strategy | Purpose | Sort opfamily
4958-
-------+-----------------+-----------------------------------------+----------+---------+---------------
4959-
btree | float_ops | < (double precision, double precision) | 1 | search |
4960-
btree | float_ops | <= (double precision, double precision) | 2 | search |
4961-
btree | float_ops | = (double precision, double precision) | 3 | search |
4962-
btree | float_ops | >= (double precision, double precision) | 4 | search |
4963-
btree | float_ops | > (double precision, double precision) | 5 | search |
4964-
btree | float_ops | < (real, real) | 1 | search |
4965-
btree | float_ops | <= (real, real) | 2 | search |
4966-
btree | float_ops | = (real, real) | 3 | search |
4967-
btree | float_ops | >= (real, real) | 4 | search |
4968-
btree | float_ops | > (real, real) | 5 | search |
4969-
btree | float_ops | < (double precision, real) | 1 | search |
4970-
btree | float_ops | <= (double precision, real) | 2 | search |
4971-
btree | float_ops | = (double precision, real) | 3 | search |
4972-
btree | float_ops | >= (double precision, real) | 4 | search |
4973-
btree | float_ops | > (double precision, real) | 5 | search |
4974-
btree | float_ops | < (real, double precision) | 1 | search |
4975-
btree | float_ops | <= (real, double precision) | 2 | search |
4976-
btree | float_ops | = (real, double precision) | 3 | search |
4977-
btree | float_ops | >= (real, double precision) | 4 | search |
4978-
btree | float_ops | > (real, double precision) | 5 | search |
4956+
List of operators of operator families
4957+
AM | Operator family | Operator | Strategy | Purpose | Sort opfamily
4958+
-------+-----------------+---------------------------------------+----------+---------+---------------
4959+
btree | float_ops | <(double precision,double precision) | 1 | search |
4960+
btree | float_ops | <=(double precision,double precision) | 2 | search |
4961+
btree | float_ops | =(double precision,double precision) | 3 | search |
4962+
btree | float_ops | >=(double precision,double precision) | 4 | search |
4963+
btree | float_ops | >(double precision,double precision) | 5 | search |
4964+
btree | float_ops | <(real,real) | 1 | search |
4965+
btree | float_ops | <=(real,real) | 2 | search |
4966+
btree | float_ops | =(real,real) | 3 | search |
4967+
btree | float_ops | >=(real,real) | 4 | search |
4968+
btree | float_ops | >(real,real) | 5 | search |
4969+
btree | float_ops | <(double precision,real) | 1 | search |
4970+
btree | float_ops | <=(double precision,real) | 2 | search |
4971+
btree | float_ops | =(double precision,real) | 3 | search |
4972+
btree | float_ops | >=(double precision,real) | 4 | search |
4973+
btree | float_ops | >(double precision,real) | 5 | search |
4974+
btree | float_ops | <(real,double precision) | 1 | search |
4975+
btree | float_ops | <=(real,double precision) | 2 | search |
4976+
btree | float_ops | =(real,double precision) | 3 | search |
4977+
btree | float_ops | >=(real,double precision) | 4 | search |
4978+
btree | float_ops | >(real,double precision) | 5 | search |
49794979
(20 rows)
49804980

49814981
\dAo * pg_catalog.jsonb_path_ops
4982-
List of operators of operator families
4983-
AM | Operator family | Operator
4984-
-----+-----------------+----------------------
4985-
gin | jsonb_path_ops | @> (jsonb, jsonb)
4986-
gin | jsonb_path_ops | @? (jsonb, jsonpath)
4987-
gin | jsonb_path_ops | @@ (jsonb, jsonpath)
4982+
List of operators of operator families
4983+
AM | Operator family | Operator | Strategy | Purpose
4984+
-----+-----------------+--------------------+----------+---------
4985+
gin | jsonb_path_ops | @>(jsonb,jsonb) | 7 | search
4986+
gin | jsonb_path_ops | @?(jsonb,jsonpath) | 15 | search
4987+
gin | jsonb_path_ops | @@(jsonb,jsonpath) | 16 | search
49884988
(3 rows)
49894989

4990-
\dAp btree float_ops
4991-
List of support functions of operator families
4992-
AM | Operator family | Left arg type | Right arg type | Number | Function
4993-
-------+-----------------+------------------+------------------+--------+---------------------
4994-
btree | float_ops | double precision | double precision | 1 | btfloat8cmp
4995-
btree | float_ops | double precision | double precision | 2 | btfloat8sortsupport
4996-
btree | float_ops | double precision | double precision | 3 | in_range
4997-
btree | float_ops | real | real | 1 | btfloat4cmp
4998-
btree | float_ops | real | real | 2 | btfloat4sortsupport
4999-
btree | float_ops | double precision | real | 1 | btfloat84cmp
5000-
btree | float_ops | real | double precision | 1 | btfloat48cmp
5001-
btree | float_ops | real | double precision | 3 | in_range
4990+
\dAp+ btree float_ops
4991+
List of support functions of operator families
4992+
AM | Operator family | Registered left type | Registered right type | Number | Function
4993+
-------+-----------------+----------------------+-----------------------+--------+------------------------------------------------------------------------------
4994+
btree | float_ops | double precision | double precision | 1 | btfloat8cmp(double precision,double precision)
4995+
btree | float_ops | double precision | double precision | 2 | btfloat8sortsupport(internal)
4996+
btree | float_ops | double precision | double precision | 3 | in_range(double precision,double precision,double precision,boolean,boolean)
4997+
btree | float_ops | real | real | 1 | btfloat4cmp(real,real)
4998+
btree | float_ops | real | real | 2 | btfloat4sortsupport(internal)
4999+
btree | float_ops | double precision | real | 1 | btfloat84cmp(double precision,real)
5000+
btree | float_ops | real | double precision | 1 | btfloat48cmp(real,double precision)
5001+
btree | float_ops | real | double precision | 3 | in_range(real,real,double precision,boolean,boolean)
50025002
(8 rows)
50035003

50045004
\dAp * pg_catalog.uuid_ops
5005-
List of support functions of operator families
5006-
AM | Operator family | Left arg type | Right arg type | Number | Function
5007-
-------+-----------------+---------------+----------------+--------+--------------------
5008-
btree | uuid_ops | uuid | uuid | 1 | uuid_cmp
5009-
btree | uuid_ops | uuid | uuid | 2 | uuid_sortsupport
5010-
btree | uuid_ops | uuid | uuid | 4 | btequalimage
5011-
hash | uuid_ops | uuid | uuid | 1 | uuid_hash
5012-
hash | uuid_ops | uuid | uuid | 2 | uuid_hash_extended
5005+
List of support functions of operator families
5006+
AM | Operator family | Registered left type | Registered right type | Number | Function
5007+
-------+-----------------+----------------------+-----------------------+--------+--------------------
5008+
btree | uuid_ops | uuid | uuid | 1 | uuid_cmp
5009+
btree | uuid_ops | uuid | uuid | 2 | uuid_sortsupport
5010+
btree | uuid_ops | uuid | uuid | 4 | btequalimage
5011+
hash | uuid_ops | uuid | uuid | 1 | uuid_hash
5012+
hash | uuid_ops | uuid | uuid | 2 | uuid_hash_extended
50135013
(5 rows)
50145014

src/test/regress/sql/psql.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1205,5 +1205,5 @@ drop role regress_partitioning_role;
12051205
\dAf btree int4
12061206
\dAo+ btree float_ops
12071207
\dAo * pg_catalog.jsonb_path_ops
1208-
\dAp btree float_ops
1208+
\dAp+ btree float_ops
12091209
\dAp * pg_catalog.uuid_ops

0 commit comments

Comments
 (0)