When I run the following code, it fails with message
The error is ERROR 1: SELECT from table mytable failed, no such table/featureclass.
from osgeo import gdal
gdal.UseExceptions()
gdal.VectorTranslate(
'/tmp/out.gpkg',
"PG:host=localhost dbname=mydatabase user=username password=mypassword port=5432",
SQLStatement='SELECT * FROM mytable',
layerName='tablenameout'
)
The following alternate syntax failed too
gdal.VectorTranslate(
'/tmp/out.gpkg',
"PG:host=localhost dbname=mydatabase user=username password=mypassword port=5432",
options='-sql "SELECT * FROM mytable" -nln layernameout'
)
With ogr2ogr and providing the same input table name and database connexion, the conversion happened correctly.
ogr2ogr -f "GPKG" /tmp/out.gpkg \
"PG:host=localhost user=username dbname=mydatabase password=mypassword port=5432" \
-sql "SELECT * FROM mytable" \
-nln tablenameout
What do I miss in my code syntax to make the Python API gdal.VectorTranslate
works to open the database with my query without error?
ogr
?'...'
instead of"..."
.