postgresqlpostgisgdalogr2ogr

ogr2ogr query with " " as separator for the command and within the query results in empty response


With ogr2ogr I query geodata from a postgis database into a Geopackage. The main attribute is "natural" which as to wrappend with " ". The query is wrapped by " ", too. This leads into a empty response / geopackage

The command is: ogr2ogr -f "GPKG" natural_EPSG4326.gpkg -nln natural_EPSG4326_point PG:"host=localhost dbname=osmdatabase user=postgres password=*********" -sql "select * from import.osm_point where "natural" <> ''"

How can I wrap the sql-command for ogr2ogr without " " to query "natural"?


Solution

  • The double quote should be escaped:

    ogr2ogr -f "GPKG" natural_EPSG4326.gpkg -nln natural_EPSG4326_point PG:"host=localhost dbname=osmdatabase user=postgres password=*********" -sql "select * from import.osm_point where \"natural\" <> ''"