Home Explore Blog CI



postgresql

60th chunk of `doc/src/sgml/ref/psql-ref.sgml`
4dce8c3aba41714e9e38b67ce5d29f24b974468ae1852e670000000100000fa0
 </variablelist>
  </para>

  <refsect3 id="app-psql-patterns" xreflabel="Patterns">
   <title>Patterns</title>

   <indexterm>
    <primary>patterns</primary>
    <secondary>in psql and pg_dump</secondary>
   </indexterm>

  <para>
   The various <literal>\d</literal> commands accept a <replaceable
   class="parameter">pattern</replaceable> parameter to specify the
   object name(s) to be displayed.  In the simplest case, a pattern
   is just the exact name of the object.  The characters within a
   pattern are normally folded to lower case, just as in SQL names;
   for example, <literal>\dt FOO</literal> will display the table named
   <literal>foo</literal>.  As in SQL names, placing double quotes around
   a pattern stops folding to lower case.  Should you need to include
   an actual double quote character in a pattern, write it as a pair
   of double quotes within a double-quote sequence; again this is in
   accord with the rules for SQL quoted identifiers.  For example,
   <literal>\dt "FOO""BAR"</literal> will display the table named
   <literal>FOO"BAR</literal> (not <literal>foo"bar</literal>).  Unlike the normal
   rules for SQL names, you can put double quotes around just part
   of a pattern, for instance <literal>\dt FOO"FOO"BAR</literal> will display
   the table named <literal>fooFOObar</literal>.
  </para>

  <para>
   Whenever the <replaceable class="parameter">pattern</replaceable> parameter
   is omitted completely, the <literal>\d</literal> commands display all objects
   that are visible in the current schema search path &mdash; this is
   equivalent to using <literal>*</literal> as the pattern.
   (An object is said to be <firstterm>visible</firstterm> if its
   containing schema is in the search path and no object of the same
   kind and name appears earlier in the search path. This is equivalent to the
   statement that the object can be referenced by name without explicit
   schema qualification.)
   To see all objects in the database regardless of visibility,
   use <literal>*.*</literal> as the pattern.
  </para>

  <para>
   Within a pattern, <literal>*</literal> matches any sequence of characters
   (including no characters) and <literal>?</literal> matches any single character.
   (This notation is comparable to Unix shell file name patterns.)
   For example, <literal>\dt int*</literal> displays tables whose names
   begin with <literal>int</literal>.  But within double quotes, <literal>*</literal>
   and <literal>?</literal> lose these special meanings and are just matched
   literally.
  </para>

  <para>
   A relation pattern that contains a dot (<literal>.</literal>) is interpreted as a schema
   name pattern followed by an object name pattern.  For example,
   <literal>\dt foo*.*bar*</literal> displays all tables whose table name
   includes <literal>bar</literal> that are in schemas whose schema name
   starts with <literal>foo</literal>.  When no dot appears, then the pattern
   matches only objects that are visible in the current schema search path.
   Again, a dot within double quotes loses its special meaning and is matched
   literally.  A relation pattern that contains two dots (<literal>.</literal>)
   is interpreted as a database name followed by a schema name pattern followed
   by an object name pattern.  The database name portion will not be treated as
   a pattern and must match the name of the currently connected database, else
   an error will be raised.
  </para>

  <para>
   A schema pattern that contains a dot (<literal>.</literal>) is interpreted
   as a database name followed by a schema name pattern.  For example,
   <literal>\dn mydb.*foo*</literal> displays all schemas whose schema name
   includes <literal>foo</literal>.  The database name portion will not be
   treated as a pattern and must match the name of the currently connected
   database, else an error will be raised.
  </para>

  <para>
   Advanced users can use regular-expression notations such as character
 

Title: psql Pattern Matching Details
Summary
This section delves into the details of pattern matching used in psql, specifically with the \d commands. It explains how patterns are used to specify object names, how case folding works, and the use of double quotes to preserve case or include special characters. It also covers the use of * and ? as wildcards, and how patterns with dots are interpreted as schema and object name patterns. Additionally, it explains how schema patterns are interpreted with dots, and mentions the use of regular expressions.