diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-04-07 23:02:16 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-04-07 23:02:21 -0400 |
commit | a3027e1e7f3d3a107ecd72d3b4d6333ea2aab6a5 (patch) | |
tree | 4fcc9b9bb3af4030fc0fd3fe3004926cbc86b54a /src/bin/psql/command.c | |
parent | f57a2f5e03054ade221e554c70e628e1ffae1b66 (diff) | |
download | postgresql-a3027e1e7f3d3a107ecd72d3b4d6333ea2aab6a5.tar.gz postgresql-a3027e1e7f3d3a107ecd72d3b4d6333ea2aab6a5.zip |
Allow psql's \df and \do commands to specify argument types.
When dealing with overloaded function or operator names, having
to look through a long list of matches is tedious. Let's extend
these commands to allow specification of (input) argument types
to let such results be trimmed down. Each additional argument
is treated the same as the pattern argument of \dT and matched
against the appropriate argument's type name.
While at it, fix \dT (and these new options) to recognize the
usual notation of "foo[]" for "the array type over foo", and
to handle the special abbreviations allowed by the backend
grammar, such as "int" for "integer".
Greg Sabino Mullane, revised rather significantly by me
Discussion: https://postgr.es/m/CAKAnmmLF9Hhu02N+s7uAyLc5J1xZReg72HQUoiKhNiJV3_jACQ@mail.gmail.com
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index e04ccc5b628..543401c6d6a 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -72,6 +72,9 @@ static backslashResult exec_command_copyright(PsqlScanState scan_state, bool act static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch); static backslashResult exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd); +static bool exec_command_dfo(PsqlScanState scan_state, const char *cmd, + const char *pattern, + bool show_verbose, bool show_system); static backslashResult exec_command_edit(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf); static backslashResult exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, @@ -790,7 +793,8 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) case 'p': case 't': case 'w': - success = describeFunctions(&cmd[2], pattern, show_verbose, show_system); + success = exec_command_dfo(scan_state, cmd, pattern, + show_verbose, show_system); break; default: status = PSQL_CMD_UNKNOWN; @@ -811,7 +815,8 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) success = listSchemas(pattern, show_verbose, show_system); break; case 'o': - success = describeOperators(pattern, show_verbose, show_system); + success = exec_command_dfo(scan_state, cmd, pattern, + show_verbose, show_system); break; case 'O': success = listCollations(pattern, show_verbose, show_system); @@ -951,6 +956,45 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd) return status; } +/* \df and \do; messy enough to split out of exec_command_d */ +static bool +exec_command_dfo(PsqlScanState scan_state, const char *cmd, + const char *pattern, + bool show_verbose, bool show_system) +{ + bool success; + char *arg_patterns[FUNC_MAX_ARGS]; + int num_arg_patterns = 0; + + /* Collect argument-type patterns too */ + if (pattern) /* otherwise it was just \df or \do */ + { + char *ap; + + while ((ap = psql_scan_slash_option(scan_state, + OT_NORMAL, NULL, true)) != NULL) + { + arg_patterns[num_arg_patterns++] = ap; + if (num_arg_patterns >= FUNC_MAX_ARGS) + break; /* protect limited-size array */ + } + } + + if (cmd[1] == 'f') + success = describeFunctions(&cmd[2], pattern, + arg_patterns, num_arg_patterns, + show_verbose, show_system); + else + success = describeOperators(pattern, + arg_patterns, num_arg_patterns, + show_verbose, show_system); + + while (--num_arg_patterns >= 0) + free(arg_patterns[num_arg_patterns]); + + return success; +} + /* * \e or \edit -- edit the current query buffer, or edit a file and * make it the query buffer |