[gdal-dev] Gdal and SQLite

Even Rouault even.rouault at spatialys.com
Tue Dec 23 09:41:56 PST 2014


Le mardi 23 décembre 2014 14:33:39, Federico Jurio a écrit :
> Hi guys, i'm trying to make a simple query using sqlite through gdal
> library ( http://www.gdal.org/ogr_sql.html )
> 
> I have a simple table with two columns: ID and (asd*) (both columns have
> integer values)
> 
> I want the minimun value of this columns
> 
> My first attempt was successful
> 
> E:\Pruebas>ogrinfo -sql "select min(id) MINID from Geo1" Geo1.shp
> INFO: Open of `Geo1.shp'
>       using driver `ESRI Shapefile' successful.
> 
> Layer name: Geo1
> Geometry: None
> Feature Count: 1
> Layer SRS WKT:
> (unknown)
> MINID: Integer (10.0)
> OGRFeature(Geo1):0
>   MINID (Integer) = 2
> 
> My second attempt was unsuccessful
> 
> E:\Pruebas>ogrinfo -sql "select min((asd*)) MINASD from Geo1" Geo1.shp
> INFO: Open of `Geo1.shp'
>       using driver `ESRI Shapefile' successful.
> ERROR 1: SQL Expression Parsing Error: syntax error, unexpected ')'.
> Occured around :
> select min((asd*)) MINASD from Geo1
> 
> E:\Pruebas>ogrinfo -sql "select min("(asd*)") MINASD from Geo1" Geo1.shp
> INFO: Open of `Geo1.shp'
>       using driver `ESRI Shapefile' successful.
> ERROR 1: SQL Expression Parsing Error: syntax error, unexpected ')'.
> Occured around :
> select min((asd*)) MINASD from Geo1

Federico,

A column name like (asd*) is asking for trouble.... For some reason the 
grammar of the OGR SQL parser rejects that as an argument for MIN.

I'd note that in your message you are mentionning that you want to use the 
SQLite engine, but in the above, you won't. For that you must add "-dialect 
sqlite" to your command line. And if you do so, it will work actually.

$ ogrinfo test.csv -sql 'select min("(asd*)") from test' -dialect sqlite
INFO: Open of `test.csv'
      using driver `CSV' successful.

Layer name: SELECT
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
min("(asd*)"): Integer (0.0)
OGRFeature(SELECT):0
  min("(asd*)") (Integer) = 3

Even

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


More information about the gdal-dev mailing list