I would like to have a .psqlrc
file with default values, and be able to override these values from psql
's command line.
For example :
- have some values set in
.psqlrc
:
-- .psqlrc :
-- "user@database # " in bold green
\set PROMPT1 '%[%033[1;32;40m%]%n@%/%[%033[0m%]% > '
-- store command history in home directory, with a per database file :
\set HISTFILE ~/.psql-history- :DBNAME
- in some wrapper script
master-psql.sh
, which connects as userpostgres
, be able to override these values :
# master-psql.sh :
# when using this script, change color to red, change history file location :
psql -U postgres \
-v PROMPT1='%[%033[1;31;40m%]%n@%/%[%033[0m%]% # ' \
-v HISTFILE='/some/other/place/.psql_history_postgres'
The above does not work, because the the -v ...
argument is executed before the .psqlrc
file is loaded, and the instruction in .psqlrc
overwrites the existing value.
Question
Is there a way to instruct psql
to run a set of commands after loading its .psqlrc
file(s),
or to have .psqlrc
execute some \set
or \pset
command only if value is not set ?