3

I have a shapefile that I'm trying to filter by date (i.e. START_DATE). This same query START_DATE = '2007-07-25' works in the Attribute Table > Select features using Expression, but not in the Query Builder (Right-click) where I get this error:

An error occurred when executing the query.
The data provider said:
OGR[3] error 1: Type mismatch or improper type of arguments to = operator.

Is there a workaround this issue to show only the features (vectors) that are of interest to me.

I'm using QGIS 2.8.9 on Windows with GDAL/OGR 2.0.2.

4

Try the TimeManager plugin: https://anitagraser.com/projects/time-manager. I've created it for exactly this use case.

Click the "Settings" button in the TimeManager panel and configure the (Shapefile) layer. If you want to filter by day, change the time frame size from 1 minute to 1 day.

3

Look into this, it is Even Rouault's answer to the OGR ticket

"The issue is that binary comparisons of date/datetime field have never (yet) been implemented in OGR SQL dialect. In 1.10 and before, in fact, it turned to be an implicit conversion to string, which can cause really strange behaviour.

For example, you could have well used

"select * from test2 where date < 'bla'" 

and it would not have complained. Or

-sql "select * from test2 where date = '1969/02/11'" 

would return 3 results as expected, but

-sql "select * from test2 where date = '1969-02-11'" 

none...

1.11 just rejects implicit comparison between date and string literals. You can still get the old behaviour by expliciting casting the date field to character, with :

-sql "select * from test2 where cast(date as character) < '1970/01/01'". 
  • I came across that link but I think the cast function isn't recognized either by the Query Builder. Is there another way to filter the shapes that appear in QGIS, by entering the SQL query above somewhere else? – Hakim Oct 23 '17 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.