-- psql customizations
-- most of them were swiped from:
-- http://robots.thoughtbot.com/improving-the-command-line-postgres-experience/
--
-- Other good sources of info:
-- http://www.craigkerstiens.com/2013/02/13/How-I-Work-With-Postgres/
-- http://www.postgresql.org/docs/9.3/static/app-psql.html
-- http://arjanvandergaag.nl/blog/working-with-postgresql-on-the-command-line.html
-- https://www.periscope.io/blog/optimizing-your-psql.html
--
-- Note: <C-r> should work for searching query history (like bash), but doesn't
-- currently work with Postgres.app. See https://github.com/PostgresApp/PostgresApp/issues/144

-- Custom prompt
-- Note: %# is # if you're a superuser, otherwise >
\set PROMPT1 '%[%033[1m%]%M %n@%/%#%[%033[0m%] '

-- By default, NULL displays as an empty space. Is it actually an empty
-- string, or is it null? This makes that distinction visible.
\pset null '[NULL]'

-- Use table format (with headers across the top) by default, but switch to
-- expanded table format when there's a lot of data, which makes it much
-- easier to read.
\x auto

-- Table display options
\pset linestyle unicode
\pset border 2

-- Verbose error reports.
\set VERBOSITY verbose

-- Use a separate history file per-database.
\set HISTFILE ~/.psql_history- :DBNAME

-- If a command is run more than once in a row, only store it once in the
-- history.
\set HISTCONTROL ignoredups
\set HISTSIZE 20000
\set HISTFILE ~/.psql_history_ :DBNAME

\set ON_ERROR_STOP on
\set ON_ERROR_ROLLBACK interactive

-- Autocomplete keywords (like SELECT) in upper-case, even if you started
-- typing them in lower case.
\set COMP_KEYWORD_CASE upper

-- Show query runtime information
\timing on