From e67e61ae789b09c98fe03378c819224d838c2f65 Mon Sep 17 00:00:00 2001 From: Corey Huinker Date: Fri, 25 Jan 2019 00:57:23 +0000 Subject: [PATCH] Add \describe commands to compliment \d commands --- doc/src/sgml/ref/psql-ref.sgml | 175 ++++++++++++++++++++++++--------- src/bin/psql/command.c | 132 ++++++++++++++++++++++++- src/bin/psql/describe.c | 13 ++- src/bin/psql/describe.h | 3 + src/bin/psql/tab-complete.c | 135 ++++++++++++++++++++----- 5 files changed, 381 insertions(+), 77 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 6c76cf2f00..363d6d9678 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -871,6 +871,17 @@ testdb=> same line. + + The family of meta-commands starting with \d often + have an equivalent \describe- "long form" command. + The long-form commands often have the suffixes -system + and -verbose which are the equivalent of the + short form suffixes S and + + respectively. The long form suffixes cannot be used on the short form + variants. Every \describe variant has an equivalent + short form variant. + + The following meta-commands are defined: @@ -1133,6 +1144,7 @@ testdb=> \d[S+] [ pattern ] + \describe[-system][-verbose] [ pattern ] @@ -1151,13 +1163,13 @@ testdb=> - For some types of relation, \d shows additional information + For some types of relation, \d (and \describe shows additional information for each column: column values for sequences, indexed expressions for indexes, and foreign data wrapper options for foreign tables. - The command form \d+ is identical, except that + The command forms \d+ and \describe-verbose are identical to \d, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table, the view definition if the relation is a view, a non-default @@ -1167,13 +1179,13 @@ testdb=> By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S modifier for \d or -verbose modifier for \describe modifier to include system objects. - If \d is used without a + If \d / \describe is used without a pattern argument, it is equivalent to \dtvmsE which will show a list of all visible tables, views, materialized views, sequences and @@ -1186,6 +1198,7 @@ testdb=> \da[S] [ pattern ] + \describe-aggregate[-system] [ pattern ] @@ -1194,7 +1207,7 @@ testdb=> class="parameter">pattern is specified, only aggregates whose names match the pattern are shown. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S/-system modifier to include system objects. @@ -1202,13 +1215,14 @@ testdb=> \dA[+] [ pattern ] + \describe-access-method[-verbose] [ pattern ] Lists access methods. If pattern is specified, only access methods whose names match the pattern are shown. If - + is appended to the command name, each access + +/-verbose is appended to the command name, each access method is listed with its associated handler function and description. @@ -1216,13 +1230,14 @@ testdb=> \db[+] [ pattern ] + \describe-tablespace[-verbose] [ pattern ] Lists tablespaces. If pattern is specified, only tablespaces whose names match the pattern are shown. - If + is appended to the command name, each tablespace + If +/-verbose is appended to the command name, each tablespace is listed with its associated options, on-disk size, permissions and description. @@ -1232,6 +1247,7 @@ testdb=> \dc[S+] [ pattern ] + \describe-conversion[-system][-verbose] [ pattern ] Lists conversions between character-set encodings. @@ -1239,9 +1255,9 @@ testdb=> is specified, only conversions whose names match the pattern are listed. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S/-system modifier to include system objects. - If + is appended to the command name, each object + If +/-verbose is appended to the command name, each object is listed with its associated description. @@ -1250,13 +1266,14 @@ testdb=> \dC[+] [ pattern ] + \describe-cast[-verbose] [ pattern ] Lists type casts. If pattern is specified, only casts whose source or target types match the pattern are listed. - If + is appended to the command name, each object + If +/-verbose is appended to the command name, each object is listed with its associated description. @@ -1265,6 +1282,11 @@ testdb=> \dd[S] [ pattern ] + \describe-constraint[-system] [ pattern ] + \describe-operator-class[-system] [ pattern ] + \describe-operator-family[-system] [ pattern ] + \describe-rule[-system] [ pattern ] + \describe-trigger[-system] [ pattern ] Shows the descriptions of objects of type constraint, @@ -1279,7 +1301,7 @@ testdb=> objects of the appropriate type if no argument is given. But in either case, only objects that have a description are listed. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S/-system modifier to include system objects. @@ -1294,15 +1316,16 @@ testdb=> \dD[S+] [ pattern ] + \describe-domain[-system][-verbose] [ pattern ] Lists domains. If pattern is specified, only domains whose names match the pattern are shown. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S/-system modifier to include system objects. - If + is appended to the command name, each object + If +/-verbose is appended to the command name, each object is listed with its associated permissions and description. @@ -1311,6 +1334,7 @@ testdb=> \ddp [ pattern ] + \describe-default-access-privelege [ pattern ] Lists default access privilege settings. An entry is shown for @@ -1338,6 +1362,11 @@ testdb=> \ds[S+] [ pattern ] \dt[S+] [ pattern ] \dv[S+] [ pattern ] + \describe-index[-system][-verbose] [ pattern ] + \describe-materialized-view[-system][-verbose] [ pattern ] + \describe-sequence[-system][-verbose] [ pattern ] + \describe-table[-system][-verbose] [ pattern ] + \describe-view[-system][-verbose] [ pattern ] @@ -1346,16 +1375,22 @@ testdb=> t, and v stand for foreign table, index, materialized view, sequence, table, and view, respectively. - You can specify any or all of + In the short forms, you can specify any or all of these letters, in any order, to obtain a listing of objects of these types. For example, \dit lists indexes - and tables. If + is + and tables. If +/-verbose is appended to the command name, each object is listed with its physical size on disk and its associated description, if any. + \describe-foreign-table is equivalent to \dE. + \describe-index is equivalent to \di. + \describe-materialized-view is equivalent to \dm. + \describe-sequence is equivalent to \ds. + \describe-table is equivalent to \dt. + \describe-view is equivalent to \dv. If pattern is specified, only objects whose names match the pattern are listed. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S/-system modifier to include system objects. @@ -1364,13 +1399,14 @@ testdb=> \des[+] [ pattern ] + \describe-foreign-servers[-verbose] [ pattern ] Lists foreign servers (mnemonic: external servers). If pattern is specified, only those servers whose name matches the pattern - are listed. If the form \des+ is used, a + are listed. If the forms \des+ or \describe-foreign-server-verbose are used, a full description of each server is shown, including the server's access privileges, type, version, options, and description. @@ -1380,13 +1416,14 @@ testdb=> \det[+] [ pattern ] + \describe-foreign-table[-verbose] [ pattern ] Lists foreign tables (mnemonic: external tables). If pattern is specified, only entries whose table name or schema name matches - the pattern are listed. If the form \det+ - is used, generic options and the foreign table description + the pattern are listed. If the forms \det+ or \describe-foreign-table-verbose + are used, generic options and the foreign table description are also displayed. @@ -1395,19 +1432,20 @@ testdb=> \deu[+] [ pattern ] + \describe-user-mapping[-verbose] [ pattern ] Lists user mappings (mnemonic: external users). If pattern is specified, only those mappings whose user names match the - pattern are listed. If the form \deu+ is + pattern are listed. If the forms \deu+ or \describe-user-mapping-verboze are used, additional information about each mapping is shown. - \deu+ might also display the user name and + \deu+ and \describe-user-mapping-verboze might also display the user name and password of the remote user, so care should be taken not to disclose them. @@ -1418,14 +1456,15 @@ testdb=> \dew[+] [ pattern ] + \describe-foreign-data-wrapper[-verbose] [ pattern ] Lists foreign-data wrappers (mnemonic: external wrappers). If pattern is specified, only those foreign-data wrappers whose name matches - the pattern are listed. If the form \dew+ - is used, the access privileges, options, and description of the + the pattern are listed. If the forms \dew+ or \describe-foreign-data-wrapper-verbose + are used, the access privileges, options, and description of the foreign-data wrapper are also shown. @@ -1434,25 +1473,37 @@ testdb=> \df[anptwS+] [ pattern ] + \describe-function[-system][-verbose] [ pattern ] + \describe-normal-function[-system][-verbose] [ pattern ] + \describe-procedure[-system][-verbose] [ pattern ] + \describe-aggregate-function[-system][-verbose] [ pattern ] + \describe-trigger-function[-system][-verbose] [ pattern ] + \describe-window-function[-system][-verbose] [ pattern ] Lists functions, together with their result data types, argument data types, and function types, which are classified as agg (aggregate), normal, procedure, trigger, or window. - To display only functions + In the short form, to display only functions of specific type(s), add the corresponding letters a, n, p, t, or w to the command. If pattern is specified, only functions whose names match the pattern are shown. By default, only user-created - objects are shown; supply a pattern or the S + objects are shown; supply a pattern or the S/-system modifier to include system objects. - If the form \df+ is used, additional information + If the form \df+ or the -verbose suffix is used, additional information about each function is shown, including volatility, parallel safety, owner, security classification, access privileges, language, source code and description. + \describe-function is the equivalent of \df. + \describe-normal-function is the equivalent of \dff. + \describe-procedure is the equivalent of \dfp. + \describe-aggregate-function is the equivalent of \dfa. + \describe-trigger-function is the equivalent of \dft. + \describe-window-function is the equivalent of \dfw. @@ -1468,12 +1519,13 @@ testdb=> \dF[+] [ pattern ] + \describe-text-search-configuration[-verbose] [ pattern ] Lists text search configurations. If pattern is specified, only configurations whose names match the pattern are shown. - If the form \dF+ is used, a full description of + If the form \dF+ or \describe-text-search-configuration-verbose is used, a full description of each configuration is shown, including the underlying text search parser and the dictionary list for each parser token type. @@ -1482,12 +1534,13 @@ testdb=> \dFd[+] [ pattern ] + \describe-text-search-dictionary[-verbose] [ pattern ] Lists text search dictionaries. If pattern is specified, only dictionaries whose names match the pattern are shown. - If the form \dFd+ is used, additional information + If the form \dFd+ or \describe-text-search-dictionary-verbose is used, additional information is shown about each selected dictionary, including the underlying text search template and the option values. @@ -1496,12 +1549,13 @@ testdb=> \dFp[+] [ pattern ] + \describe-text-search-parser[-verbose] [ pattern ] Lists text search parsers. If pattern is specified, only parsers whose names match the pattern are shown. - If the form \dFp+ is used, a full description of + If the form \dFp+ or \describe-text-search-parser-verbose is used, a full description of each parser is shown, including the underlying functions and the list of recognized token types. @@ -1510,12 +1564,13 @@ testdb=> \dFt[+] [ pattern ] + \describe-text-search-template[-verbose] [ pattern ] Lists text search templates. If pattern is specified, only templates whose names match the pattern are shown. - If the form \dFt+ is used, additional information + If the form \dFt+ or \describe-text-search-template-verbose is used, additional information is shown about each template, including the underlying function names. @@ -1524,6 +1579,7 @@ testdb=> \dg[S+] [ pattern ] + \describe-role[-system][-verbose] [ pattern ] Lists database roles. @@ -1531,10 +1587,10 @@ testdb=> unified into roles, this command is now equivalent to \du.) By default, only user-created roles are shown; supply the - S modifier to include system roles. + S or -system modifier to include system roles. If pattern is specified, only those roles whose names match the pattern are listed. - If the form \dg+ is used, additional information + If the suffix + or -verbose> is specified, additional information is shown about each role; currently this adds the comment for each role. @@ -1554,14 +1610,15 @@ testdb=> \dL[S+] [ pattern ] + \describe-procedural-language[-system][-verbose] [ pattern ] Lists procedural languages. If pattern is specified, only languages whose names match the pattern are listed. By default, only user-created languages - are shown; supply the S modifier to include system - objects. If + is appended to the command name, each + are shown; supply the S or -system modifier to include system + objects. If + or -verbose is appended to the command name, each language is listed with its call handler, validator, access privileges, and whether it is a system object. @@ -1571,6 +1628,8 @@ testdb=> \dn[S+] [ pattern ] + \describe-schema[-system][-verbose] [ pattern ] + \describe-namespace[-system][-verbose] [ pattern ] @@ -1578,8 +1637,8 @@ testdb=> class="parameter">pattern is specified, only schemas whose names match the pattern are listed. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system objects. - If + is appended to the command name, each object + pattern or the S or -system modifier to include system objects. + If + (or -verbose is appended to the command name, each object is listed with its associated permissions and description, if any. @@ -1588,15 +1647,16 @@ testdb=> \do[S+] [ pattern ] + \describe-operator[-system][-verbose] [ pattern ] Lists operators with their operand and result types. If pattern is specified, only operators whose names match the pattern are listed. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S or -system modifier to include system objects. - If + is appended to the command name, + If + or -verbose is appended to the command name, additional information about each operator is shown, currently just the name of the underlying function. @@ -1606,14 +1666,15 @@ testdb=> \dO[S+] [ pattern ] + \describe-collation[-system][-verbose] [ pattern ] Lists collations. If pattern is specified, only collations whose names match the pattern are listed. By default, only user-created objects are shown; - supply a pattern or the S modifier to - include system objects. If + is appended + supply a pattern or the S or -system modifier to + include system objects. If + or -verbose is appended to the command name, each collation is listed with its associated description, if any. Note that only collations usable with the current database's encoding @@ -1626,6 +1687,7 @@ testdb=> \dp [ pattern ] + \describe-privilege [ pattern ] Lists tables, views and sequences with their @@ -1647,6 +1709,7 @@ testdb=> \drds [ role-pattern [ database-pattern ] ] + \describe-defined-configuration-setting [ role-pattern [ database-pattern ] ] Lists defined configuration settings. These settings can be @@ -1669,13 +1732,14 @@ testdb=> \dRp[+] [ pattern ] + \describe-replication-publication[-verbose] [ pattern ] Lists replication publications. If pattern is specified, only those publications whose names match the pattern are listed. - If + is appended to the command name, the tables + If + or -verbose is appended to the command name, the tables associated with each publication are shown as well. @@ -1683,13 +1747,14 @@ testdb=> \dRs[+] [ pattern ] + \describe-replication-subscription[-verbose] [ pattern ] Lists replication subscriptions. If pattern is specified, only those subscriptions whose names match the pattern are listed. - If + is appended to the command name, additional + If + or -verbose is appended to the command name, additional properties of the subscriptions are shown. @@ -1697,16 +1762,17 @@ testdb=> \dT[S+] [ pattern ] + \describe-type[-system][-verbose] [ pattern ] Lists data types. If pattern is specified, only types whose names match the pattern are listed. - If + is appended to the command name, each type is + If + or -verbose is appended to the command name, each type is listed with its internal name and size, its allowed values if it is an enum type, and its associated permissions. By default, only user-created objects are shown; supply a - pattern or the S modifier to include system + pattern or the S or -system modifier to include system objects. @@ -1714,6 +1780,7 @@ testdb=> \du[S+] [ pattern ] + \describe-role[S+] [ pattern ] Lists database roles. @@ -1721,10 +1788,10 @@ testdb=> unified into roles, this command is now equivalent to \dg.) By default, only user-created roles are shown; supply the - S modifier to include system roles. + S or -system modifier to include system roles. If pattern is specified, only those roles whose names match the pattern are listed. - If the form \du+ is used, additional information + If the suffix + or -verbose is used, additional information is shown about each role; currently this adds the comment for each role. @@ -1733,13 +1800,14 @@ testdb=> \dx[+] [ pattern ] + \describe-extension[-verbose] [ pattern ] Lists installed extensions. If pattern is specified, only those extensions whose names match the pattern are listed. - If the form \dx+ is used, all the objects belonging + If the suffix + or -verbose is used, all the objects belonging to each matching extension are listed. @@ -1747,15 +1815,24 @@ testdb=> \dy[+] [ pattern ] + \describe-event-trigger[-verbose] [ pattern ] Lists event triggers. If pattern is specified, only those event triggers whose names match the pattern are listed. - If + is appended to the command name, each object + If + or -verbose is appended to the command name, each object is listed with its associated description. + + + + Long form commands can aid in clarity when sharing code with others. + Using tab completion can reduce typing and aid in the discovery of new + \describe commands. + + @@ -2291,7 +2368,7 @@ SELECT character set encodings, and access privileges. If pattern is specified, only databases whose names match the pattern are listed. - If + is appended to the command name, database + If + (or -verbose in the long form) is appended to the command name, database sizes, default tablespaces, and descriptions are also displayed. (Size information is only available for databases that the current user can connect to.) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index ab259c473a..a27be4d916 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -685,6 +685,12 @@ exec_command_crosstabview(PsqlScanState scan_state, bool active_branch) return status; } +static +bool cmd_match(const char* str, const char* pattern) +{ + return (strncmp(str, pattern, strlen(pattern)) == 0); +} + /* * \d* commands */ @@ -853,7 +859,131 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) switch (cmd[2]) { case 's': - success = listForeignServers(pattern, show_verbose); + if (cmd[3] != 'c') + { + /* no \describe, just \des */ + success = listForeignServers(pattern, show_verbose); + break; + } + else if (!cmd_match(cmd,"describe")) + { + status = PSQL_CMD_UNKNOWN; + break; + } + else + { + /* Allow -verbose suffix but keep '+' */ + if (strstr(cmd, "-verbose") != NULL) + show_verbose = true; + /* Allow -system suffix but keep 'S' */ + if (strstr(cmd, "-system") != NULL) + show_system = true; + + if (cmd_match(cmd,"describe-aggregate-function")) + success = describeAggregates(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-access-method")) + success = describeAccessMethods(pattern, show_verbose); + else if (cmd_match(cmd, "describe-tablespace")) + success = describeTablespaces(pattern, show_verbose); + else if (cmd_match(cmd, "describe-conversion")) + success = listConversions(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-cast")) + success = listCasts(pattern, show_verbose); + else if (cmd_match(cmd, "describe-constraint") || + cmd_match(cmd, "describe-operator-class") || + cmd_match(cmd, "describe-operator-family") || + cmd_match(cmd, "describe-rule") || + cmd_match(cmd, "describe-trigger")) + success = objectDescription(pattern, show_system); + else if (cmd_match(cmd, "describe-domain")) + success = listDomains(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-default-access-privelege ")) + success = listDefaultACLs(pattern); + else if (cmd_match(cmd, "describe-foreign-server")) + success = listForeignServers(pattern, show_verbose); + else if (cmd_match(cmd, "describe-foreign-table")) + success = listForeignTables(pattern, show_verbose); + else if (cmd_match(cmd, "describe-index")) + success = listTables("i", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-materialized-view")) + success = listTables("m", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-sequence")) + success = listTables("s", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-table")) + success = listTables("t", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-view")) + success = listTables("v", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-user-mapping")) + success = listUserMappings(pattern, show_verbose); + else if (cmd_match(cmd, "describe-foreign-data-wrapper")) + success = listForeignDataWrappers(pattern, show_verbose); + else if (cmd_match(cmd, "describe-function")) + success = describeFunctions("\0", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-procedure")) + success = describeFunctions("p", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-trigger-function")) + success = describeFunctions("t", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-window-function")) + success = describeFunctions("w", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-normal-function")) + success = describeFunctions("n", pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-text-search-configuration")) + success = listTSConfigs(pattern, show_verbose); + else if (cmd_match(cmd, "describe-text-search-dictionary")) + success = listTSDictionaries(pattern, show_verbose); + else if (cmd_match(cmd, "describe-text-search-parser")) + success = listTSParsers(pattern, show_verbose); + else if (cmd_match(cmd, "describe-text-search-templates")) + success = listTSTemplates(pattern, show_verbose); + else if (cmd_match(cmd, "describe-role")) + success = describeRoles(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-procedural-language")) + success = listLanguages(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-schema") || + cmd_match(cmd, "describe-namespace")) + success = listSchemas(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-operator")) + success = describeOperators(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-collation")) + success = listCollations(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-privilege ")) + success = permissionsList(pattern); + else if (cmd_match(cmd, "describe-defined-configuration-setting ")) + { + char *pattern2 = NULL; + + if (pattern) + pattern2 = psql_scan_slash_option(scan_state, + OT_NORMAL, NULL, true); + success = listDbRoleSettings(pattern, pattern2); + + if (pattern2) + free(pattern2); + } + else if (cmd_match(cmd, "describe-replication-publication")) + if (show_verbose) + success = describePublications(pattern); + else + success = listPublications(pattern); + else if (cmd_match(cmd, "describe-replication-subscription")) + success = describeSubscriptions(pattern, show_verbose); + else if (cmd_match(cmd, "describe-type")) + success = describeTypes(pattern, show_verbose, show_system); + else if (cmd_match(cmd, "describe-extension")) + if (show_verbose) + success = listExtensionContents(pattern); + else + success = listExtensions(pattern); + else if (cmd_match(cmd, "describe-event-trigger")) + success = listEventTriggers(pattern, show_verbose); + else if (pattern) + /* generic describe on a specific pattern */ + success = describeTableDetails(pattern, show_verbose, show_system); + else + /* standard listing of interesting things */ + success = listTables("tvmsE", NULL, show_verbose, show_system); + } + status = PSQL_CMD_UNKNOWN; break; case 'u': success = listUserMappings(pattern, show_verbose); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 4da6719ce7..444b0a2ae4 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -54,6 +54,18 @@ static bool listOneExtensionContents(const char *extname, const char *oid); *---------------- */ +/* + * \describe + * + * The full-word version of every \d* command + */ +bool +describe(const char *words, const char *pattern, bool verbose, bool showSystem) +{ + + return true; +} + /* * \da @@ -294,7 +306,6 @@ describeTablespaces(const char *pattern, bool verbose) return true; } - /* * \df * Takes an optional regexp to select particular functions. diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index 4ff1f91f38..ff13e3bbd1 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -9,6 +9,9 @@ #define DESCRIBE_H +/* \describe, \describe-table, etc */ +extern bool describe(const char *words, const char *pattern, bool verbose, bool showSystem); + /* \da */ extern bool describeAggregates(const char *pattern, bool verbose, bool showSystem); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 292b1f483a..11821a4c86 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1400,6 +1400,51 @@ psql_completion(const char *text, int start, int end) "\\w", "\\watch", "\\z", "\\!", "\\?", + "\\describe-aggregate-function", + "\\describe-aggregate", + "\\describe-access-method", + "\\describe-tablespace", + "\\describe-conversion", + "\\describe-cast", + "\\describe-constraint", + "\\describe-operator-class", + "\\describe-operator-family", + "\\describe-rule", + "\\describe-trigger", + "\\describe-domain", + "\\describe-default-access-privelege ", + "\\describe-foreign-server", + "\\describe-foreign-table", + "\\describe-index", + "\\describe-materialized-view", + "\\describe-sequence", + "\\describe-table", + "\\describe-view", + "\\describe-user-mapping", + "\\describe-foreign-data-wrapper", + "\\describe-function", + "\\describe-procedure", + "\\describe-trigger-function", + "\\describe-window-function", + "\\describe-normal-function", + "\\describe-text-search-configuration", + "\\describe-text-search-dictionary", + "\\describe-text-search-parser", + "\\describe-text-search-templates", + "\\describe-role", + "\\describe-procedural-language", + "\\describe-schema", + "\\describe-namespace", + "\\describe-operator", + "\\describe-collation", + "\\describe-privilege ", + "\\describe-defined-configuration-setting ", + "\\describe-replication-publication", + "\\describe-replication-subscription", + "\\describe-type", + "\\describe-extension", + "\\describe-event-trigger", + "\\describe", NULL }; @@ -3460,60 +3505,98 @@ psql_completion(const char *text, int start, int end) if (!recognized_connection_string(prev_wd)) COMPLETE_WITH_QUERY(Query_for_list_of_roles); } - else if (TailMatchesCS("\\da*")) + else if (TailMatchesCS("\\df*") || + TailMatchesCS("\\describe-function*") || + TailMatchesCS("\\describe-aggregate-function*") || + TailMatchesCS("\\describe-window-function*") || + TailMatchesCS("\\describe-procedure*") || + TailMatchesCS("\\describe-normal-function*")) + COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL); + else if (TailMatchesCS("\\da*") || + TailMatchesCS("\\describe-aggregate*")) COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL); - else if (TailMatchesCS("\\dA*")) + else if (TailMatchesCS("\\dA*") || + TailMatchesCS("\\describe-access-method*")) COMPLETE_WITH_QUERY(Query_for_list_of_access_methods); - else if (TailMatchesCS("\\db*")) + else if (TailMatchesCS("\\db*") || + TailMatchesCS("\\describe-tablespace*")) COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); - else if (TailMatchesCS("\\dD*")) + else if (TailMatchesCS("\\dD*") || + TailMatchesCS("\\describe-domain*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains, NULL); - else if (TailMatchesCS("\\des*")) - COMPLETE_WITH_QUERY(Query_for_list_of_servers); - else if (TailMatchesCS("\\deu*")) + else if (TailMatchesCS("\\deu*") || + TailMatchesCS("\\describe-user-mapping*")) COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings); - else if (TailMatchesCS("\\dew*")) + else if (TailMatchesCS("\\dew*") || + TailMatchesCS("\\describe-foreign-data-wrapper*")) COMPLETE_WITH_QUERY(Query_for_list_of_fdws); - else if (TailMatchesCS("\\df*")) - COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL); - else if (TailMatchesCS("\\dFd*")) + else if (TailMatchesCS("\\dFd*") || + TailMatchesCS("\\describe-text-search-dictionary*")) COMPLETE_WITH_QUERY(Query_for_list_of_ts_dictionaries); - else if (TailMatchesCS("\\dFp*")) + else if (TailMatchesCS("\\dFp*") || + TailMatchesCS("\\describe-text-search-parser*")) COMPLETE_WITH_QUERY(Query_for_list_of_ts_parsers); - else if (TailMatchesCS("\\dFt*")) + else if (TailMatchesCS("\\dFt*") || + TailMatchesCS("\\describe-text-search-template*")) COMPLETE_WITH_QUERY(Query_for_list_of_ts_templates); /* must be at end of \dF alternatives: */ else if (TailMatchesCS("\\dF*")) COMPLETE_WITH_QUERY(Query_for_list_of_ts_configurations); - else if (TailMatchesCS("\\di*")) + else if (TailMatchesCS("\\di*") || + TailMatchesCS("\\describe-index*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL); - else if (TailMatchesCS("\\dL*")) + else if (TailMatchesCS("\\dL*") || + TailMatchesCS("\\describe-procedural-language*")) COMPLETE_WITH_QUERY(Query_for_list_of_languages); - else if (TailMatchesCS("\\dn*")) + else if (TailMatchesCS("\\dn*") || + TailMatchesCS("\\describe-schema*") || + TailMatchesCS("\\describe-namespace*")) COMPLETE_WITH_QUERY(Query_for_list_of_schemas); - else if (TailMatchesCS("\\dp") || TailMatchesCS("\\z")) + else if (TailMatchesCS("\\dp") || TailMatchesCS("\\z") || + TailMatchesCS("\\describe-privelege*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_grantables, NULL); - else if (TailMatchesCS("\\ds*")) + else if (TailMatchesCS("\\ds*") || + TailMatchesCS("\\describe-sequence*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL); - else if (TailMatchesCS("\\dt*")) + else if (TailMatchesCS("\\dt*") || + TailMatchesCS("\\describe-table*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); - else if (TailMatchesCS("\\dT*")) + else if (TailMatchesCS("\\dT*") || + TailMatchesCS("\\describe-type*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL); - else if (TailMatchesCS("\\du*") || TailMatchesCS("\\dg*")) + else if (TailMatchesCS("\\du*") || TailMatchesCS("\\dg*") || + TailMatchesCS("\\describe-role*")) COMPLETE_WITH_QUERY(Query_for_list_of_roles); - else if (TailMatchesCS("\\dv*")) + else if (TailMatchesCS("\\dv*") || + TailMatchesCS("\\describe-view*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL); - else if (TailMatchesCS("\\dx*")) + else if (TailMatchesCS("\\dx*") || + TailMatchesCS("\\describe-extension*")) COMPLETE_WITH_QUERY(Query_for_list_of_extensions); - else if (TailMatchesCS("\\dm*")) + else if (TailMatchesCS("\\dm*") || + TailMatchesCS("\\describe-materialized-view*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL); - else if (TailMatchesCS("\\dE*")) + else if (TailMatchesCS("\\dE*") || + TailMatchesCS("\\describe-foreign-table*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables, NULL); - else if (TailMatchesCS("\\dy*")) + else if (TailMatchesCS("\\dy*") || + TailMatchesCS("\\describe-event-trigger*")) COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); + /* short version \\des has conflict with \\describe */ + else if (TailMatchesCS("\\describe-foreign-server*")) + COMPLETE_WITH_QUERY(Query_for_list_of_servers); + + /* catch-all \\describe */ + else if (TailMatchesCS("\\describe*")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_relations, NULL); + + /* \\des* must go after \\describe */ + else if (TailMatchesCS("\\des*")) + COMPLETE_WITH_QUERY(Query_for_list_of_servers); + /* must be at end of \d alternatives: */ else if (TailMatchesCS("\\d*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_relations, NULL); -- 2.17.1