Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#5153 closed defect (fixed)

OGR SQL: confusion between literal that is equal to a column name

Reported by: nirvn Owned by: warmerdam
Priority: high Milestone: 2.0.0
Component: OGR_SF Version: 1.9.0
Severity: major Keywords: ogr sql
Cc:

Description

I've just hit a really strange bug. Using the attached shapefile, OGR Shapefile driver is unable to query the dataset using a simple string attribute filter and return "error 1: type mismatch or improper type of arguments to = operator".

Steps to reproduce:

  1. Use the following ogrinfo command line on the attached shapefile:

ogrinfo -al -where "PARTY_1ST = 'CPP'" "election 2012\commune_election_results_v2.shp"

This will fail, returning error 1

  1. Use the following ogrinfo command line on the attached shapefile:

ogrinfo -al -where "PARTY_1ST = 'HRP'" "election 2012\commune_election_results_v2.shp"

This will fail, returning error 1

  1. Use the following ogrinfo command line on the attached shapefile:

ogrinfo -al -where "PARTY_1ST = 'Sam Rainsy'" "election 2012\commune_election_results_v2.shp"

This will work and list the filtered features.

Change History (5)

comment:1 by nirvn, 11 years ago

Oups, turns out the shapefile is over attachment's size limit. I've uploaded the shapefile to this location: http://licadho-cambodia.org/gdal/Election2012.zip

comment:2 by Even Rouault, 11 years ago

Hum, the issue here is that the OGR SQL engine confuses the 'CPP' litteral and the CPP column. This is indeed a known issue listed in paragraph 'More stricter OGR SQL syntax to distinguish literals from identifiers' of http://trac.osgeo.org/gdal/wiki/GDAL20Changes.

One way of workarounding this for wnow is to ogr2ogr your shapefile to sqlite and then issue the request on the sqlite file.

comment:3 by Even Rouault, 11 years ago

Summary: ogr shapefile driver unable to apply simple string attribute filterOGR SQL: confusion between literal that is equal to a column name

comment:4 by Even Rouault, 9 years ago

Component: defaultOGR_SF
Keywords: ogr sql added
Milestone: 2.0
Resolution: fixed
Status: newclosed

comment:5 by Even Rouault, 9 years ago

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.