Output Formatting Examples
The first example shows how to spread a command over several lines of input. Notice the changing prompt:
=> CREATE TABLE my_table ( -> first integer not null default 0, -> second char(10)); CREATE TABLE
Assume you have filled the table with data and want to take a look at it:
testdb=> SELECT * FROM my_table; first | second -------+-------- 1 | one 2 | two 3 | three 4 | four (4 rows)
You can display tables in different ways by using the \pset
command:
testdb=> \pset border 2 Border style is 2. testdb=> SELECT * FROM my_table; +-------+--------+ | first | second | +-------+--------+ | 1 | one | | 2 | two | | 3 | three | | 4 | four | +-------+--------+ (4 rows)
=> \pset border 0 Border style is 0. => SELECT * FROM my_table; first second ----- ------ 1 one 2 two 3 three 4 four (4 rows)
=> \pset border 1 Border style is 1. => \pset format unaligned Output format is unaligned. => \pset fieldsep ',' Field separator is ",". => \pset tuples_only Showing only tuples. => SELECT second, first FROM my_table; one,1 two,2 three,3 four,4
Alternatively, use the short commands:
=> \a \t \ x Output format is aligned. Tuples only is off. Expanded display is on. => SELECT * FROM my_table; first | 1 second | one -------+----------- first | 2 second | two -------+----------- first | 3 second | three -------+----------- first | 4 second | four