Using Postgres on command line

written by Guido Percú on November 4, 2015

Learn how to be productive in psql, Postgres command line interface.

Postgres has a nice utility to work with database. You can modify the default behavior in your ~/.psqlrc file.

Example of a customized PSQL Shell

-- By default NULL displays an invisible character on the string.
-- Make it say "[NULL]"
\pset null '[NULL]'
-- Ignore duplicated rows in the history log
\set HISTCONTROL ignoredups
-- Autocomplete keywords in uppercase (SELECT, WHERE, ...)
\set COMP_KEYWORD_CASE upper
-- Shows how much time it took to run the last query
\timing
-- Formats the results of the query according to the width of your screen.
\x auto'