POTENZA
POTENZA

Reputation: 1437

how to change default public schema on the psql command line

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.

Upvotes: 4

Views: 9643

Answers (1)

mys
mys

Reputation: 2473

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

Upvotes: 12

Related Questions