Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ff481ca

Browse files
committed
Adjust processSQLNamePattern() so that $ within the pattern is always matched
literally, whether quoted or not. Since we allow $ as a character within identifiers, this behavior is useful, whereas the previous behavior of treating it as the regexp ending anchor was nearly useless given that the pattern is automatically anchored anyway. This affects the arguments of psql's \d commands as well as pg_dump's -n and -t switches. Per discussion.
1 parent 6244c2d commit ff481ca

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.192 2007/06/28 06:40:16 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.193 2007/07/10 00:21:31 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1916,8 +1916,8 @@ lo_import 152801
19161916
<para>
19171917
A pattern that contains a dot (<literal>.</>) is interpreted as a schema
19181918
name pattern followed by an object name pattern. For example,
1919-
<literal>\dt foo*.bar*</> displays all tables whose table name
1920-
starts with <literal>bar</> that are in schemas whose schema name
1919+
<literal>\dt foo*.*bar*</> displays all tables whose table name
1920+
includes <literal>bar</> that are in schemas whose schema name
19211921
starts with <literal>foo</>. When no dot appears, then the pattern
19221922
matches only objects that are visible in the current schema search path.
19231923
Again, a dot within double quotes loses its special meaning and is matched
@@ -1930,17 +1930,20 @@ lo_import 152801
19301930
expression special characters work as specified in
19311931
<xref linkend="functions-posix-regexp">, except for <literal>.</> which
19321932
is taken as a separator as mentioned above, <literal>*</> which is
1933-
translated to the regular-expression notation <literal>.*</>, and
1934-
<literal>?</> which is translated to <literal>.</>. You can emulate
1933+
translated to the regular-expression notation <literal>.*</>,
1934+
<literal>?</> which is translated to <literal>.</>, and
1935+
<literal>$</> which is matched literally. You can emulate
19351936
these pattern characters at need by writing
19361937
<literal>?</> for <literal>.</>,
19371938
<literal>(<replaceable class="parameter">R</replaceable>+|)</literal> for
19381939
<literal><replaceable class="parameter">R</replaceable>*</literal>, or
19391940
<literal>(<replaceable class="parameter">R</replaceable>|)</literal> for
19401941
<literal><replaceable class="parameter">R</replaceable>?</literal>.
1941-
Remember that the pattern must match the whole name, unlike the usual
1942-
interpretation of regular expressions; write <literal>*</> at the beginning
1943-
and/or end if you don't wish the pattern to be anchored.
1942+
<literal>$</> is not needed as a regular-expression character since
1943+
the pattern must match the whole name, unlike the usual
1944+
interpretation of regular expressions (in other words, <literal>$</>
1945+
is automatically appended to your pattern). Write <literal>*</> at the
1946+
beginning and/or end if you don't wish the pattern to be anchored.
19441947
Note that within double quotes, all regular expression special characters
19451948
lose their special meanings and are matched literally. Also, the regular
19461949
expression special characters are matched literally in operator name

src/bin/pg_dump/dumputils.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.36 2007/06/18 21:40:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/bin/pg_dump/dumputils.c,v 1.37 2007/07/10 00:21:31 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -872,6 +872,18 @@ processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern,
872872
appendPQExpBufferStr(&namebuf, "^(");
873873
cp++;
874874
}
875+
else if (ch == '$')
876+
{
877+
/*
878+
* Dollar is always quoted, whether inside quotes or not.
879+
* The reason is that it's allowed in SQL identifiers, so
880+
* there's a significant use-case for treating it literally,
881+
* while because we anchor the pattern automatically there is
882+
* no use-case for having it possess its regexp meaning.
883+
*/
884+
appendPQExpBufferStr(&namebuf, "\\$");
885+
cp++;
886+
}
875887
else
876888
{
877889
/*

0 commit comments

Comments
 (0)