[gdal-dev] How to escape special characters in an “-sql” option within an ogr2ogr command line?

list-fhi at web.de list-fhi at web.de
Fri Aug 25 02:25:55 PDT 2017


Hello,
I am using Windows 7 x64, GDAL v2.3.0dev r39906 from http://www.gisinternals.com/development.php.
Input:    https://ufile.io/i5oj3
Output:   https://uploadfiles.io/
Command line:
ogr2ogr.exe -f "GPKG" "C:\Temp\output.gpkg" "C:\Temp\input.sqlite" -overwrite -lco "SPATIAL_INDEX=NO" -lco "GEOMETRY_NAME=the_geom" -nlt "MULTIPOLYGON" -lco "GEOMETRY_NULLABLE=yes" -nln "import" -t_srs "EPSG:4326" -sql "SELECT \"OBJECTID\", \"NAME\", \"STATE_NAME\", \"STATE_FIPS\", \"CNTY_FIPS\", \"FIPS\", \"AREA\", \"POP1990\", \"POP2000\", \"POP90_SQMI\", \"!#()*+,-:;=@^_ ^|~äöüß\", \"the_geom\" FROM \"import3\";"
 
In my case I have a test Spatialite layer with an attribute named: “!#()*+,-:;=@^_ |~äöüß” (without the double quotes).
When I tried to copy the layer to a new GeoPackage layer, it failed with an.
After I escaped the “|” character with “^|” the command line worked without error.
However, the name of the attribute name in the new GeoPackage layer is empty.
 
I reckon the error involves special characters who need escaping. As everything works as expected if I don't export the "!#()*+,-:;=@^_ |~äöüß" attribute. I tried several methods of escaping some of the characters but it never worked right. Could anybody help in escaping the characters, so that the attribute name is correct in the newly created GeoPackage?


More information about the gdal-dev mailing list