-- vim: ft=sql:noml:
-- postgresql client configuration file.
-- ref: https://www.postgresql.org/docs/current/config-setting.html

-- shut up \pset during this config script.
\set QUIET on

-- 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.
\pset expanded auto

-- nicer tables
\pset linestyle unicode
-- \pset unicode_border_linestyle single
-- \pset unicode_column_linestyle single
-- \pset unicode_header_linestyle double

-- 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]'
-- \pset null '⦱'
-- \pset null '¤'

-- don't rollback the entire transaction if you typo a sql command,
-- but only in interactive mode
\set ON_ERROR_ROLLBACK interactive
-- \set ON_ERROR_STOP on

-- history
\set HISTCONTROL ignoreboth
-- set path to history file (database specific).
-- \set HISTFILE HISTFILE_PATH- :DBNAME
-- use a separate history file per-database.
\set HISTFILE ~/.local/state/psql_history- :DBNAME
\set HISTSIZE 100000

-- always show how long a query takes
\timing

-- a prompt with transaction information
-- add transaction status (%x) to prompt; show database name in bold green.
-- \set PROMPT1 '%x%[%033[01;32m%]%/%[%033[00m%]%R%# '
-- \set PROMPT1 '%[%033[33;1m%]%x%[%033[0m%]%[%033[1m%]%/%[%033[0m%]%R%# '
-- \set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%# '
-- \set PROMPT2 '[more] %R > '
-- \set PROMPT1 '(%n@%M:%/) psql> '
\set PROMPT1 '%~%#%x '
-- \x auto
-- remove database from second prompt to make it easily distinguishable from
-- PROMPT1.
\set PROMPT2 '%x%R%# '

-- disable default pager
\pset pager off
\setenv LESS '-iMFXSx4R'

-- verbose error reports.
\set VERBOSITY verbose

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

-- "psql shortcut to save/restore original PROMPT1 setting
-- -- add to .psqlrc before changing PROMPT1
-- -- restores PROMPT1 to original setting
-- -- to use enter ":reset_prompt" (w/o quotes)
-- SELECT FORMAT($$\set PROMPT1 '%s'$$, :'PROMPT1') AS reset_prompt \gset"

-- but display the normal psql welcome message.
\set QUIET off
