[gdal-dev] How to escape "desc" with OGR SQL?

Even Rouault even.rouault at spatialys.com
Thu Jun 16 10:27:14 PDT 2016


Le jeudi 16 juin 2016 19:18:16, Jukka Rahkonen a écrit :
> Hi,
> 
> I had a need to convert  some data into GPX format and populate the GPX
> attributes "name" and "desc". Name was not any problem as can be tested
> with ogrinfo -sql "select attr_1 as name from test" test.shp
> 
> However, "desc" is a SQL keyword for descending order and all my trials
> with OGR SQL failed like this:
> ogrinfo -sql "select attr_2 as "desc" from test" test.shp

On Windows shell I suppose ? Perhaps with \" (not tried)

ogrinfo -sql "select attr_2 as \"desc\" from test" test.shp


On Linux bash the following - using single quote for the full SQL - also works 
(not sure on Windows)

ogrinfo -sql 'select attr_2 as "desc" from test' test.shp


> ERROR 1: SQL Expression Parsing Error: syntax error, unexpected DESC,
> expecting identifier. Occurred around :
> select attr_2 as desc from test
>                  ^
> I managed to do the job with SQLite dialect but I wonder if I found a bug
> with using "desc" as an identifier.

Probably SQLite is more tolerant about using reserved keywords in non-
ambiguous situations.

> 
> -Jukka Rahkonen-
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list