OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.64k stars 2.45k forks source link

ogr2ogr - PostgreSQL driver : option 'active_schema' returns an error but writes the datas anyway #2868

Open MaelREBOUX opened 3 years ago

MaelREBOUX commented 3 years ago

context and actual behavior

ogr2ogr is used in a fmous QGIS plugin : https://github.com/3liz/QgisCadastrePlugin/

As I wanted to load the raw EDIGEO datas to make dev tests, I ran :

"C:\Program Files\QGIS\3.10\bin\ogr2ogr.exe" -s_srs "EPSG:3948" -t_srs "EPSG:3948" -f "PostgreSQL" PG:"host=localhost port=5432 dbname=test active_schema=cadastre_qgis user=cadastre_qgis password=cadastre_qgis" Z:\donnees_edigeo\test\com-001\feuille-0010000A01\E0000A01.THF -lco GEOMETRY_NAME=geom -lco PG_USE_COPY=YES -nlt GEOMETRY -gt 50000 --config OGR_EDIGEO_CREATE_LABEL_LAYERS NO

Then the ouput is :

ERROR 1: PQconnectdb failed: invalid connection option "active_schema"
ERROR 1: Couldn't establish a database connection

So I thinked that any data was write in the database but no : all the expected datas in the tables are here.

Expected behavior

No error message ?

Steps to reproduce the problem.

Get some EDIGEO files here : https://cadastre.data.gouv.fr/data/dgfip-pci-vecteur/2020-01-01/edigeo/departements/

Get QGIS to use the embeded GDAL / ogr2ogr

and run the command line above (point out a THF file)

Operating system

Windows 10 pro

GDAL version and provenance

GDAL 3.0.4, released 2020/01/28 embedded in QGIS 3.10.6

rouault commented 3 years ago

I can't reproduce on Linux. The active_schema option is supposed to be stripped off from the connection string before being passed to PQconnectdb(). Is your above connection string exactly the one you've used ? I assume you've redacted the password part, but is there possibly strings in the value of some connection parameters ?

MaelREBOUX commented 3 years ago

Sorry : a pb with copy-paste with a trunked line in the shell. The command line is the right one now.

seidlmic commented 3 years ago

I can see same behaviour with gdal 2.4.4. and PG12. Connection string returns Error but data are actually in.

~/apps/bin/ogr2ogr --config GDAL_DATA ~/apps/share/gdal/ -f "PostgreSQL" PG:"dbname='shkn' active_schema=_test_shp host='127.0.0.1' port=5432 user='ogr2ogr' password='lopata'" plynovod.shp

ERROR 1: PQconnectdb failed: invalid connection option "active_schema"
ERROR 1: Couldn't establish a database connection

I have also found others face this problem https://stackoverrun.com/fr/q/10620579 https://stackoverflow.com/questions/38535670/can-i-set-search-path-when-importing-a-shape-file-with-ogr2ogr-from-gdal

Also while other connection parameters allow quotation active_schema no. The error appears 3 times.I have omitted some blank lines from output

 ~/apps/bin/ogr2ogr --config GDAL_DATA ~/apps/share/gdal/ -f "PostgreSQL" PG:"dbname='shkn' active_schema='_test_shp' host='127.0.0.1' port=5432 user='ogr2ogr' password='lopata'" plynovod.shp

ERROR 1: PQconnectdb failed: invalid connection option "active_schema"
ERROR 1: Couldn't establish a database connection
ERROR 1: ERROR:  syntax error at or near "_test_shp"
LINE 1: SET search_path=''_test_shp'',public
ERROR 1: ERROR:  syntax error at or near "_test_shp"
LINE 1: SET search_path=''_test_shp'',public
ERROR 1: ERROR:  syntax error at or near "_test_shp"
LINE 1: SET search_path=''_test_shp'',public
ERROR 1: PostgreSQL driver doesn't currently support database creation.
Please create database with the `createdb' command.
ERROR 1: PostgreSQL driver failed to create PG:dbname='shkn' active_schema='_test_shp' host='127.0.0.1' port=5432 user='ogr2ogr' password=XXXXXXXX
seidlmic commented 3 years ago

And there is also missing example promised in documentation on page https://gdal.org/drivers/vector/pg.html in section Layer creation options for SCHEMA parametr

Fuzl commented 2 years ago

Same here ! Any ideas ?