I'm importing shape files into Postgresql via this command:
ogr2ogr PG:host=localhost dbname=someDbName user=someUserName password=somePassword shapeFile.shp -nln alternateLayerName -nlt someValidGeometry
This works well but goes into public
schema in Postgresql. I'd like to choose a different schema. Is there a way to achieve this with ogr2ogr
alone?
There's no reference in man ogr2ogr
to schema. My web search wasn't fruitful either.
I know I can do an ALTER TABLE some_table set schema a_different_schema
, but that would mean adding another step to the process.
$ ogr2ogr --version
GDAL 2.1.0, released 2016/04/25
After a better web search I found on GDAL pg driver documentation that one can use ACTIVE_SCHEMA=string: Active schema.
to set the schema where the table will be created.
I tried it like this:
ogr2ogr -f "PostgreSQL" PG:"dbname=mydb active_schema=layers" country.shp -nln test_table -nlt MULTILINESTRING
And it complains with:
ERROR 1: PQconnectdb failed: invalid connection option "active_schema"
But table gets created and populated properly. So I guess it's ok.