Bug report #11318

using date fields in QGIS 2.4 query builder

Added by Stewart Sinclair almost 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:2.4.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:19614

Description

In QGIS 2.2 I could use a query such as

"Started" > '2014/07/17'

to find all records later than the date given. In QGIS 2.4.0 this results in the error:

"OGR3 error 1: Type mismatch or improper type of arguments to > operator."

History

#1 Updated by Stewart Sinclair almost 6 years ago

this problem applies to shape files (the expression still works with PostGis files) and comparison between date fields is OK in shape files. The problem seems to be specifying the date constant.

#2 Updated by Stewart Sinclair almost 6 years ago

Just to clarify:

"Started" > '2014-05-17' will select records in the "Select by expression" window but causes the error when entered into the "Query Builder" for the "Feature subset" filter.

#3 Updated by Giovanni Manghi almost 6 years ago

  • Status changed from Open to Feedback
  • Category set to Vectors

Stewart Sinclair wrote:

Just to clarify:

"Started" > '2014-05-17' will select records in the "Select by expression" window but causes the error when entered into the "Query Builder" for the "Feature subset" filter.

but in the query builder used to work until 2.2? Could you please attach sample data?

#4 Updated by Nathan Woodrow almost 6 years ago

Just note that that query string is passed to ogr to process. The problem might live there rather then in QGIS.

#5 Updated by Giovanni Manghi almost 6 years ago

Nathan Woodrow wrote:

Just note that that query string is passed to ogr to process. The problem might live there rather then in QGIS.

yes, this is why I asked. It seems strange to me that it worked in previous qgis releases, as the query builder uses ogr.

#6 Updated by Stewart Sinclair almost 6 years ago

I found that this problem had already been raised but no solution given.

Casting the date field ("Started") works in the Query Builder filter:

cast("Started" as character) > '2014/07/05'

but not in the select window where it is not required.

See http://gis.stackexchange.com/questions/99991/how-to-filter-date-values-using-ogr-1-11-0

#7 Updated by Giovanni Manghi almost 6 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

Stewart Sinclair wrote:

I found that this problem had already been raised but no solution given.

Casting the date field ("Started") works in the Query Builder filter:

cast("Started" as character) > '2014/07/05'

but not in the select window where it is not required.

See http://gis.stackexchange.com/questions/99991/how-to-filter-date-values-using-ogr-1-11-0

So as the query builder uses ogr (and now qgis ships with gdal/ogr 1.11 on most platforms) users must use the correct ogr syntax, in this case the one that was described in that page on stackexchange and this ogr ticket http://trac.osgeo.org/gdal/ticket/5507

Also available in: Atom PDF