Book Contents

Book Index

Next Topic

Home

Output Formatting Examples

The first example shows how to spread a command over several lines of input. Notice the changing prompt:

testdb=> CREATE TABLE my_table (

testdb(> first integer not null default 0,

testdb(> second text) testdb-> ;

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)

testdb=> \pset border 0

Border style is 0.

testdb=> SELECT * FROM my_table;

first second

----- ------

1 one

2 two

3 three

4 four

(4 rows)

testdb=>

\pset border 1

Border style is 1.

testdb=> \pset format unaligned

Output format is unaligned.

testdb=> \pset fieldsep ","

Field separator is ",".

testdb=> \pset tuples_only

Showing only tuples.

testdb=> SELECT second, first FROM my_table; one,1

two,2

three,3

four,4

Alternatively, use the short commands:

testdb=> \a \t \ x

Output format is aligned.

Tuples only is off.

Expanded display is on.

testdb=> SELECT * FROM my_table;

-[ RECORD 1 ]-

first | 1

second | one

-[ RECORD 2 ]-

first | 2

second | two

-[ RECORD 3 ]-

first | 3

second | three

-[ RECORD 4 ]-

first | 4

second | four