Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5047 closed defect (invalid)

ogr2ogr -sql syntax error

Reported by: sbl Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.9.2
Severity: normal Keywords: SQL
Cc:

Description (last modified by sbl)

When converting from shapefile to shapefile (or to PostGIS) ogr2ogr invoked with -sql statement throws error message: "ERROR 1: SQL Expression Parsing Error: syntax error" Even with a simple syntax like: ""SELECT * FROM mylayer". Happend on Ubuntu 12.04 server.

Change History (5)

comment:1 Changed 5 years ago by Even Rouault

Resolution: invalid
Status: newclosed

I'm pretty sure at 99.9% it is just a typo on your side. This is a basic function well tested by the regression tests. And in your description, there's actually a typo : the double double-quote at the beginning of the SQL.

comment:2 Changed 5 years ago by sbl

Description: modified (diff)

comment:3 Changed 5 years ago by sbl

Description: modified (diff)

I see that it is a fundamental and widely used function, and I will try to find out what could have went wrong on my side. Maybe something went wrong when I compiled GDAL, but I tested lots of different sql-statments and got allways a syntax error... The typo in the description would not have led to an error message at all because the system would waited for the end of the command...

comment:4 Changed 5 years ago by Even Rouault

Another hypothesis is that your "mylayer" is a SQL reserved keyword for example.

For example :

ogrinfo poly.shp -sql "select * from order"
INFO: Open of `poly.shp'
      using driver `ESRI Shapefile' successful.
ERROR 1: SQL Expression Parsing Error: syntax error

comment:5 Changed 5 years ago by sbl

Thanks, now I found out what was wrong:
The layer names started with a number which obviously is invalid in SQL...

ogr2ogr -sql "SELECT * FROM 32_0626arealressurs_linje" test.shp 32_0626arealressurs_linje.shp -progress
ERROR 1: SQL Expression Parsing Error: syntax error

ogr2ogr test.shp 32_0626arealressurs_linje.shp -progress
0...10...20...30...40...50...60...70...80...90...100 - done.

ogr2ogr -sql "SELECT * FROM test" test_2.shp test.shp -progress
0...10...20...30...40...50...60...70...80...90...100 - done.


Thanks again and sorry for the noise...

Note: See TracTickets for help on using tickets.