[gdal-dev] how to use the filter option -where within an mysql request?

Even Rouault even.rouault at mines-paris.org
Tue Dec 20 07:50:42 EST 2011


Stefan,

Please always mention the GDAL/OGR version you are using in your reports. It
will save the readers from figuring out from the error message that you must use
GDAL 1.7.x or an earlier version.

The -where "end_measure = '2011-12-20'" clause doesn't work in GDAL 1.7.x or
earlier because the code didn't support comparison on DateTime fields (the error
message mentions list of binary fields, but DateTime fields too)

I've done a quick test on GDAL 1.9.0beta1 and you can use comparisons on date,
but they seem to be string based. And you have to respect the format of the
string serialization used by OGR. In your case, it would be -where "end_measure
= '2011/12/20  0:00:00'"

However, there's no advantage of using -where when you already use -sql. The
-sql is directly forwarded to the SQL engine of the RDBMS (when the OGR driver
is the one of a RDBMS of course), so it will run faster than -where which,
depending on situations, can be evaluated on OGR side.
- On a layer which is already the result of -sql, the -where clause is always
evaluated on OGR side, after the evaluation of -sql
- If the layer is directly a table name, then the -where clause is generally
forwarded to the server. (It might depend on the OGR driver however).

So, as a rule of thumb, you can remember that there's no point in using both
-sql and -where.

Best regards,

Even


More information about the gdal-dev mailing list