从 GDAL 导入带有 ogr2ogr 的形状文件时,我可以设置 search_path 吗?

Can I set search_path when importing a shape file with ogr2ogr from GDAL?

我正在通过此命令将形状文件导入 Postgresql:

ogr2ogr PG:host=localhost dbname=someDbName user=someUserName password=somePassword shapeFile.shp -nln alternateLayerName -nlt someValidGeometry

这很好用,但进入了 Postgresql 中的 public 模式。我想选择不同的模式。有没有办法单独使用 ogr2ogr 来实现这一目标?

man ogr2ogr 中没有对 架构 的引用。我的网络搜索也没有结果。

我知道我可以做一个 ALTER TABLE some_table set schema a_different_schema,但这意味着要在流程中添加另一个步骤。

$ ogr2ogr --version GDAL 2.1.0, released 2016/04/25

经过更好的网络搜索后,我在 GDAL pg driver documentation 上发现可以使用 ACTIVE_SCHEMA=string: Active schema. 设置将创建 table 的架构。

我这样试过:

ogr2ogr -f "PostgreSQL" PG:"dbname=mydb active_schema=layers" country.shp -nln test_table -nlt MULTILINESTRING

它抱怨:

ERROR 1: PQconnectdb failed: invalid connection option "active_schema"

但 table 已正确创建和填充。所以我觉得还可以。

我使用 lco 选项找到了更好的解决方案:

ogr2ogr -f PostgreSQL "PG:host=localhost port=5432 dbname=some_db
user=postgres password=" someShapeFile.shp -nln desiredTableName
-nlt someValidGeometry -lco SCHEMA=desiredPostgresqlSchema