Skip to content

Commit b0b5e20

Browse files
committed
Show opclass and opfamily related information in psql
This commit provides psql commands for listing operator classes, operator families and its contents in psql. New commands will be useful for exploring capabilities of both builtin opclasses/opfamilies as well as opclasses/opfamilies defined in extensions. Discussion: https://postgr.es/m/1529675324.14193.5.camel%40postgrespro.ru Author: Sergey Cherkashin, Nikita Glukhov, Alexander Korotkov Reviewed-by: Michael Paquier, Alvaro Herrera, Arthur Zakirov Reviewed-by: Kyotaro Horiguchi, Andres Freund
1 parent 691e8b2 commit b0b5e20

File tree

8 files changed

+676
-2
lines changed

8 files changed

+676
-2
lines changed

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,97 @@ testdb=>
12311231
</listitem>
12321232
</varlistentry>
12331233

1234+
<varlistentry>
1235+
<term>
1236+
<literal>\dAc[+]
1237+
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
1238+
[<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
1239+
</literal>
1240+
</term>
1241+
<listitem>
1242+
<para>
1243+
Lists operator classes
1244+
(see <xref linkend="catalog-pg-opclass"/>).
1245+
If <replaceable class="parameter">access-method-patttern</replaceable>
1246+
is specified, only operator classes associated with access methods whose
1247+
names match pattern are listed.
1248+
If <replaceable class="parameter">input-type-pattern</replaceable>
1249+
is specified, only operator classes associated with input types whose
1250+
names match the pattern are listed.
1251+
If <literal>+</literal> is appended to the command name, each operator
1252+
class is listed with its associated operator family and owner.
1253+
</para>
1254+
</listitem>
1255+
</varlistentry>
1256+
1257+
<varlistentry>
1258+
<term>
1259+
<literal>\dAf[+]
1260+
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
1261+
[<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
1262+
</literal>
1263+
</term>
1264+
<listitem>
1265+
<para>
1266+
Lists operator families
1267+
(see <xref linkend="catalog-pg-opfamily"/>).
1268+
If <replaceable class="parameter">access-method-patttern</replaceable>
1269+
is specified, only operator families associated with access methods whose
1270+
names match pattern are listed.
1271+
If <replaceable class="parameter">input-type-pattern</replaceable>
1272+
is specified, only operator families associated with input types whose
1273+
names match the pattern are listed.
1274+
If <literal>+</literal> is appended to the command name, each operator
1275+
family is listed with its owner.
1276+
</para>
1277+
</listitem>
1278+
</varlistentry>
1279+
1280+
<varlistentry>
1281+
<term>
1282+
<literal>\dAo[+]
1283+
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
1284+
[<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
1285+
</literal>
1286+
</term>
1287+
1288+
<listitem>
1289+
<para>
1290+
Lists operators associated with operator families
1291+
(<xref linkend="catalog-pg-amop"/>).
1292+
If <replaceable class="parameter">access-method-patttern</replaceable>
1293+
is specified, only members of operator families associated with access
1294+
methods whose names match pattern are listed.
1295+
If <replaceable class="parameter">input-type-pattern</replaceable>
1296+
is specified, only memeber of operator families whose names match the
1297+
pattern are listed.
1298+
If <literal>+</literal> is appended to the command name, each operator
1299+
is listed with its strategy number, purpose and sort operator family.
1300+
</para>
1301+
</listitem>
1302+
</varlistentry>
1303+
1304+
<varlistentry>
1305+
<term>
1306+
<literal>\dAp[+]
1307+
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
1308+
[<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
1309+
</literal>
1310+
</term>
1311+
<listitem>
1312+
<para>
1313+
Lists procedures associated with operator families
1314+
(<xref linkend="catalog-pg-amproc"/>).
1315+
If <replaceable class="parameter">access-method-patttern</replaceable>
1316+
is specified, only members of operator families associated with access
1317+
methods whose names match pattern are listed.
1318+
If <replaceable class="parameter">input-type-pattern</replaceable>
1319+
is specified, only memeber of operator families whose names match the
1320+
pattern are listed.
1321+
</para>
1322+
</listitem>
1323+
</varlistentry>
1324+
12341325
<varlistentry>
12351326
<term><literal>\db[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
12361327

src/bin/psql/command.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,38 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
721721
success = listTables("tvmsE", NULL, show_verbose, show_system);
722722
break;
723723
case 'A':
724-
success = describeAccessMethods(pattern, show_verbose);
724+
{
725+
char *pattern2 = NULL;
726+
727+
if (pattern && cmd[2] != '\0' && cmd[2] != '+')
728+
pattern2 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, true);
729+
730+
switch (cmd[2])
731+
{
732+
case '\0':
733+
case '+':
734+
success = describeAccessMethods(pattern, show_verbose);
735+
break;
736+
case 'c':
737+
success = listOperatorClasses(pattern, pattern2, show_verbose);
738+
break;
739+
case 'f':
740+
success = listOperatorFamilies(pattern, pattern2, show_verbose);
741+
break;
742+
case 'o':
743+
success = listOpFamilyOperators(pattern, pattern2, show_verbose);
744+
break;
745+
case 'p':
746+
success = listOpFamilyProcedures(pattern, pattern2);
747+
break;
748+
default:
749+
status = PSQL_CMD_UNKNOWN;
750+
break;
751+
}
752+
753+
if (pattern2)
754+
free(pattern2);
755+
}
725756
break;
726757
case 'a':
727758
success = describeAggregates(pattern, show_verbose, show_system);

0 commit comments

Comments
 (0)