How to set a search_path default on a psql cmd execution?
I finally found it, its not a psql option, but it fits a oneliner:
PGOPTIONS=--search_path=myschema psql -h myHost -U myUser -dmyDb -p myPort
.
If anybody improves it with a working version call for both unix and windows ill approve
You could use the .psqlrc
file, which is run at psql startup:
$ echo 'set search_path to foo,bar' >> ~/.psqlrc
$ psql ...
You can specify a PGOPTIONS-style connstring as an argument to psql
instead of using the -d
/-h
/-U
/-p
/etc options. For your example:
psql 'host=myHost user=myUser dbname=myDb port=myPort options=--search_path=myschema'
or, if you prefer the URI style,
psql 'postgresql://myUser@myHost:myPort/myDb?options=--search_path%3dmyschema'
See the "Connection strings" section of the manual for details.