diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-10-10 16:15:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-10-10 16:15:37 +0000 |
commit | 7b165e3ba54da7c845bb0f7236fcb08656361a96 (patch) | |
tree | bdac41d31b5bba3f94cf0ae56547ccb4357776dd | |
parent | f3fa771ccf905ad1c1c2ab6bfab7ece0c02bef39 (diff) | |
download | postgresql-7b165e3ba54da7c845bb0f7236fcb08656361a96.tar.gz |
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.
-rw-r--r-- | src/bin/psql/describe.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index df0acafa21..7570e644e1 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.87.2.2 2006/10/07 22:21:57 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.87.2.3 2006/10/10 16:15:37 tgl Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -1737,16 +1737,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); } } @@ -1764,24 +1759,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); } } |