Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change default public schema on the psql command line

Tags:

postgresql

In order to load a MS Access mdb file into PostgreSQL, I type the following command on the psql command line.

mdb-schema xxx.mdb postgres | psql -h xxx -U xxx -W -d xxx

However, the Postgres tables are made under the default public schema. I want to have them under a different schema ("network"), rather than the default schema("public"). Could you please tell me how to change from "public" to "network" in this situation?

I appreciate any suggestions.

like image 238
POTENZA Avatar asked Dec 15 '22 16:12

POTENZA


1 Answers

You need to set PGOPTIONS:

mdb-schema xxx.mdb postgres | PGOPTIONS='-c search_path=network' psql -h xxx -U xxx -W -d xxx

and here is the proof (set schema to test_schema):

$ PGOPTIONS='-c search_path=test_schema' psql postgres -c 'show search_path'
 search_path 
-------------
 test_schema
(1 row)

Using PGOPTIONS you can set (almost) any configuration directive

like image 99
mys Avatar answered Mar 15 '23 16:03

mys