aboutsummaryrefslogtreecommitdiff
path: root/src/fe_utils/string_utils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-04-07 23:02:16 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-04-07 23:02:21 -0400
commita3027e1e7f3d3a107ecd72d3b4d6333ea2aab6a5 (patch)
tree4fcc9b9bb3af4030fc0fd3fe3004926cbc86b54a /src/fe_utils/string_utils.c
parentf57a2f5e03054ade221e554c70e628e1ffae1b66 (diff)
downloadpostgresql-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/fe_utils/string_utils.c')
-rw-r--r--src/fe_utils/string_utils.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c
index 9a1ea9ab98b..5b206c7481d 100644
--- a/src/fe_utils/string_utils.c
+++ b/src/fe_utils/string_utils.c
@@ -1062,10 +1062,16 @@ patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf, PQExpBuffer schemabuf,
* regexp errors. Outside quotes, however, let them pass through
* as-is; this lets knowledgeable users build regexp expressions
* that are more powerful than shell-style patterns.
+ *
+ * As an exception to that, though, always quote "[]", as that's
+ * much more likely to be an attempt to write an array type name
+ * than it is to be the start of a regexp bracket expression.
*/
if ((inquotes || force_escape) &&
strchr("|*+?()[]{}.^$\\", ch))
appendPQExpBufferChar(curbuf, '\\');
+ else if (ch == '[' && cp[1] == ']')
+ appendPQExpBufferChar(curbuf, '\\');
i = PQmblen(cp, encoding);
while (i-- && *cp)
{