I'm trying to import a dataset (file GDB) into a PostgreSQL (16) + PostGIS (3.4) database using GDAL 3.6.3 (released 2023/03/07) without any kind of success:
ogr2ogr -f PostgreSQL "PG:${PG_URI}" -doo ACTIVE_SCHEMA=my_schema "${file_gdb}"
Warning 1: -doo ignored when creating the output datasource.
also:
ogr2ogr -f PostgreSQL "PG:${PG_URI}" -lco SCHEMA=my_schema "${file_gdb}"
Warning 1: Layer creation options ignored since an existing layer is
being appended to.
or:
ogr2ogr -f PostgreSQL "PG:${PG_URI}" -dsco SCHEMA=my_schema "${file_gdb}"
Warning 6: driver PostgreSQL does not support creation option SCHEMA
I also tried to expand the connection parameters one by one (but I truly want to use a URI connection string):
ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5432 dbname=mydb user=myuser password=mypassword ACTIVE_SCHEMA=my_schema" "${file_gdb}"
This takes time and doesn't raise anything special but it writes tables to the public schema.
From here, two tightly related questions:
- do I have to manually create the PostgreSQL schema before using
ogr2ogr? - how to specify the target schema (in both cases: it already exists/it doesn't already exist) when importing a dataset such as a file GDB (it can be a GPKG)? By default, the
publicschema is used.
Doc:
https://gdal.org/drivers/vector/pg.html#dataset-open-options
https://gdal.org/programs/ogr2ogr.html
-dscocannot work because the driver does not support any datastore creation options gdal.org/drivers/vector/pg.html. And-doois a dataset open option and does not affect writing. It is not documented that GDAL cannot create a new schema, but if you try, you'll see a message likeERROR 1: Schema "theschema" does not exist.Your second command should work but the warning suggests that you have already a table with the same name.-nlnparameter. For example:ogr2ogr .... -nln my_schema.my_layername ... my_source