Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering by ranges in datastore API

Tags:

ckan

The datastore API documentation at http://docs.ckan.org/en/ckan-2.2/datastore.html describes how methods such as "datastore_delete" or "datastore_search" can include a "filter" parameter to filter results.

filters (dictionary) – filters to apply before deleting (eg {“name”: “fred”}). If missing delete whole table and all dependent views. (optional)

Taking into account the {"name": "fred"} example, it seems that filtering is based in exact matching. However, is it also possible to specify a range, e.g. get results greater/lesser than a given value?

For example, if I have a datastore with a field named "date" with values from "2014-06-12T12:03:10.052000" (oldest) to "2014-06-12T16:08:39.542000" (newest) in my record, how I can get for example the records older to 2014-06-12T14:00:00 or newer to 2014-06-12T15:00:00?

Any example or pointer to documentation is welcome. Thanks!

like image 819
fgalan Avatar asked Jun 28 '26 23:06

fgalan


1 Answers

The answer is that, as of CKAN 2.2, this is not possible. the datastore_delete and datastore_search actions only take filters of the type "field = value".

For datastore_search there is an alternative: datastore_search_sql which allows you to provide your own SQL query, and thus implement range searches. (I think the limitations are that this only works on public datasets, and requires a read only database user, which CKAN only supports for Postgres 9.1+).

There is an experimental branch, 1725 currently being developed which will allow plugins to extend the SQL queries ran by the datastore. This will allow plugins to implement new types of filter, such as ranges. If you are a developer you may want to try that branch.

like image 170
Alice Heaton Avatar answered Jul 01 '26 20:07

Alice Heaton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!