Home Explore Blog CI



postgresql

81th chunk of `doc/src/sgml/ref/psql-ref.sgml`
eac42574fea869f4cd6766cbd3694ecf2b8a9007905621df000000010000095a
 0</userinput>
Border style is 0.
peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table;</userinput>
first second
----- ------
    1 one
    2 two
    3 three
    4 four
(4 rows)

peter@localhost testdb=&gt; <userinput>\pset border 1</userinput>
Border style is 1.
peter@localhost testdb=&gt; <userinput>\pset format csv</userinput>
Output format is csv.
peter@localhost testdb=&gt; <userinput>\pset tuples_only</userinput>
Tuples only is on.
peter@localhost testdb=&gt; <userinput>SELECT second, first FROM my_table;</userinput>
one,1
two,2
three,3
four,4
peter@localhost testdb=&gt; <userinput>\pset format unaligned</userinput>
Output format is unaligned.
peter@localhost testdb=&gt; <userinput>\pset fieldsep '\t'</userinput>
Field separator is "    ".
peter@localhost testdb=&gt; <userinput>SELECT second, first FROM my_table;</userinput>
one     1
two     2
three   3
four    4
</programlisting>
  Alternatively, use the short commands:
<programlisting>
peter@localhost testdb=&gt; <userinput>\a \t \x</userinput>
Output format is aligned.
Tuples only is off.
Expanded display is on.
peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table;</userinput>
-[ RECORD 1 ]-
first  | 1
second | one
-[ RECORD 2 ]-
first  | 2
second | two
-[ RECORD 3 ]-
first  | 3
second | three
-[ RECORD 4 ]-
first  | 4
second | four
</programlisting>
  </para>

  <para>
  Also, these output format options can be set for just one query by using
  <literal>\g</literal>:
<programlisting>
peter@localhost testdb=&gt; <userinput>SELECT * FROM my_table</userinput>
peter@localhost testdb-&gt; <userinput>\g (format=aligned tuples_only=off expanded=on)</userinput>
-[ RECORD 1 ]-
first  | 1
second | one
-[ RECORD 2 ]-
first  | 2
second | two
-[ RECORD 3 ]-
first  | 3
second | three
-[ RECORD 4 ]-
first  | 4
second | four
</programlisting>
  </para>

  <para>
   Here is an example of using the <command>\df</command> command to
   find only functions with names matching <literal>int*pl</literal>
   and whose second argument is of type <type>bigint</type>:
<programlisting>
testdb=&gt; <userinput>\df int*pl * bigint</userinput>
                          List of functions
   Schema   |  Name   | Result data type | Argument data types | Type
------------+---------+------------------+---------------------+------
 pg_catalog | int28pl | bigint           | smallint, bigint    | func
 pg_catalog

Title: psql Examples: Output Formatting and Function Listing
Summary
The examples demonstrate various ways to format query output in psql using \pset, including border styles, CSV format, unaligned format, and field separators. It also shows how to use short commands like \a, \t, and \x to quickly change output format options and how to apply these options to a single query using \g. Finally, it provides an example of using \df to filter and list functions based on name and argument types.