]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix psql \d commands to behave properly when a pattern using regex | is given.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Oct 2006 16:15:28 +0000 (16:15 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Oct 2006 16:15:28 +0000 (16:15 +0000)
Formerly they'd emit '^foo|bar$' which is wrong because the anchors are
parsed as part of the alternatives; must emit '^(foo|bar)$' to get expected
behavior.  Same as bug found previously in similar_escape().  Already fixed
in HEAD, this is just back-porting the part of that patch that was a bug fix.

src/bin/psql/describe.c

index 03df20b95e9902b92928d51111360ca22ffe78fb..d292d183137db7bc9718006699045830de0ae292 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.111.4.1 2006/10/07 22:21:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.111.4.2 2006/10/10 16:15:28 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -1889,16 +1889,11 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
        {
                /* We have a schema pattern, so constrain the schemavar */
 
-               appendPQExpBufferChar(&schemabuf, '$');
-               /* Optimize away ".*$", and possibly the whole pattern */
-               if (schemabuf.len >= 3 &&
-                       strcmp(schemabuf.data + (schemabuf.len - 3), ".*$") == 0)
-                       schemabuf.data[schemabuf.len - 3] = '\0';
-
-               if (schemabuf.data[0] && schemavar)
+               /* Optimize away a "*" pattern */
+               if (strcmp(schemabuf.data, ".*") != 0 && schemavar)
                {
                        WHEREAND();
-                       appendPQExpBuffer(buf, "%s ~ '^%s'\n",
+                       appendPQExpBuffer(buf, "%s ~ '^(%s)$'\n",
                                                          schemavar, schemabuf.data);
                }
        }
@@ -1916,24 +1911,19 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
        {
                /* We have a name pattern, so constrain the namevar(s) */
 
-               appendPQExpBufferChar(&namebuf, '$');
-               /* Optimize away ".*$", and possibly the whole pattern */
-               if (namebuf.len >= 3 &&
-                       strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0)
-                       namebuf.data[namebuf.len - 3] = '\0';
-
-               if (namebuf.data[0])
+               /* Optimize away a "*" pattern */
+               if (strcmp(namebuf.data, ".*") != 0)
                {
                        WHEREAND();
                        if (altnamevar)
                                appendPQExpBuffer(buf,
-                                                                 "(%s ~ '^%s'\n"
-                                                                 "        OR %s ~ '^%s')\n",
+                                                                 "(%s ~ '^(%s)$'\n"
+                                                                 "        OR %s ~ '^(%s)$')\n",
                                                                  namevar, namebuf.data,
                                                                  altnamevar, namebuf.data);
                        else
                                appendPQExpBuffer(buf,
-                                                                 "%s ~ '^%s'\n",
+                                                                 "%s ~ '^(%s)$'\n",
                                                                  namevar, namebuf.data);
                }
        }