8000 Fix psql \d commands to behave properly when a pattern using regex | … · danielcode/postgres@7275173 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7275173

Browse files
committed
Fix psql \d commands to behave properly when a pattern using regex | is given.
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.
1 parent b25ddbb commit 7275173

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/bin/psql/describe.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.71.2.2 2006/10/07 22:22:04 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.71.2.3 2006/10/10 16:15:42 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -1534,16 +1534,11 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
15341534
{
15351535
/* We have a schema pattern, so constrain the schemavar */
15361536

1537-
appendPQExpBufferChar(&schemabuf, '$');
1538-
/* Optimize away ".*$", and possibly the whole pattern */
1539-
if (schemabuf.len >= 3 &&
1540-
strcmp(schemabuf.data + (schemabuf.len - 3), ".*$") == 0)
1541-
schemabuf.data[schemabuf.len - 3] = '\0';
1542-
1543-
if (schemabuf.data[0] && schemavar)
1537+
/* Optimize away a "*" pattern */
1538+
if (strcmp(schemabuf.data, ".*") != 0 && schemavar)
15441539
{
15451540
WHEREAND();
1546-
appendPQExpBuffer(buf, "%s ~ '^%s'\n",
1541+
appendPQExpBuffer(buf, "%s ~ '^(%s)$'\n",
15471542
schemavar, schemabuf.data);
15481543
}
15491544
}
@@ -1561,24 +1556,19 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
15611556
{
15621557
/* We have a name pattern, so constrain the namevar(s) */
15631558

1564-
appendPQExpBufferChar(&namebuf, '$');
1565-
/* Optimize away ".*$", and possibly the whole pattern */
1566-
if (namebuf.len >= 3 &&
1567-
strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0)
1568-
namebuf.data[namebuf.len - 3] = '\0';
1569-
1570-
if (namebuf.data[0])
1559+
/* Optimize away a "*" pattern */
1560+
if (strcmp(namebuf.data, ".*") != 0)
15711561
{
15721562
WHEREAND();
15731563
if (altnamevar)
15741564
appendPQExpBuffer(buf,
1575-
"(%s ~ '^%s'\n"
1576-
" OR %s ~ '^%s')\n",
1565+
"(%s ~ '^(%s)$'\n"
1566+
" OR %s ~ '^(%s)$')\n",
15771567
namevar, namebuf.data,
15781568
altnamevar, namebuf.data);
15791569
else
15801570
appendPQExpBuffer(buf,
1581-
"%s ~ '^%s'\n",
1571+
"%s ~ '^(%s)$'\n",
15821572
namevar, namebuf.data);
15831573
}
15841574
}

0 commit comments

Comments
 (0)
0