From 727517363673caec1f3a376f20862ab2e52fcec7 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 10 Oct 2006 16:15:42 +0000 Subject: [PATCH] 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. --- src/bin/psql/describe.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 270e9a87bc8..09985c123f0 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.71.2.2 2006/10/07 22:22:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.71.2.3 2006/10/10 16:15:42 tgl Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -1534,16 +1534,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); } } @@ -1561,24 +1556,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); } } -- 2.39.5