[ckan-dev] Empty datastore table in CKAN

Michael Nielsen mic.niel84 at gmail.com
Wed Feb 24 19:09:09 UTC 2016


So line 309, filters = data_dict.pop('filters', None), should that just be
commented out / removed?
Or is there more to it?

On Wed, Feb 24, 2016 at 6:09 PM, Tyler Kennedy <tk at tkte.ch> wrote:

> My apologies, that first link should be:
>
>
> https://github.com/ckan/ckan/blob/f74575024a472085db2c8238d8f0ff71d888ffaf/ckanext/datastore/logic/action.py#L309
>
> Thank you,
> Tyler Kennedy
>
> On Wed, Feb 24, 2016 at 12:02 PM, Tyler Kennedy <tk at tkte.ch> wrote:
>
>> This line:
>>
>>
>> https://github.com/ckan/ckan/blob/f74575024a472085db2c8238d8f0ff71d888ffaf/ckanext/datastore/db.py#L1169
>>
>> Is removing the filters argument from data_dict. This means that when
>> db.delete is finally called here:
>>
>>
>> https://github.com/ckan/ckan/blob/f74575024a472085db2c8238d8f0ff71d888ffaf/ckanext/datastore/db.py#L1169
>>
>> ... that the database will always be deleted.
>>
>> This is a bug, I will send a PR to correct this shortly.
>>
>> Thank you,
>> Tyler Kennedy
>>
>> On Wed, Feb 24, 2016 at 11:46 AM, Michael Nielsen <mic.niel84 at gmail.com>
>> wrote:
>>
>>> Parsing 'filters': {} actually deletes the table, not just the rows.
>>>
>>> On Wed, Feb 24, 2016 at 3:06 PM, Ian Ward <ian at excess.org> wrote:
>>>
>>>> I don't think this was the question originally asked, but to remove
>>>> all rows with datastore_delete without deleting the table you need to
>>>> pass "filters": {} or similar. If you omit filters completely the
>>>> table iteself will be removed. Would be great to make this clearer in
>>>> the docs.
>>>>
>>>> We don't currently offer a way to delete rows with sql expressions
>>>> like ">". You could issue that kind of update directly with SQL (if
>>>> you have access) or iterate over all the rows to delete with separate
>>>> datastore_delete calls.
>>>>
>>>> On Wed, Feb 24, 2016 at 8:13 AM, Vitor Baptista <
>>>> vitor at vitorbaptista.com> wrote:
>>>> > (As answered in stackoverflow)
>>>> >
>>>> > To delete a datastore table's contents without deleting its
>>>> structure, you
>>>> > simply call "datastore_delete" without passing any "filters".
>>>> >
>>>> > On 24 February 2016 at 12:41, Michael Nielsen <mic.niel84 at gmail.com>
>>>> wrote:
>>>> >>
>>>> >> Question also asked at
>>>> >>
>>>> http://stackoverflow.com/questions/35598133/delete-all-records-with-id-higher-than-x-in-ckan
>>>> .
>>>> >>
>>>> >> I'm trying to use the datastore_api in CKAN (ckan.org) and want to
>>>> delete
>>>> >> all records with an id higher than X - my goal is simply to delete
>>>> ALL
>>>> >> records without deleting the table.
>>>> >>
>>>> >> Docs:
>>>> >>
>>>> http://docs.ckan.org/en/ckan-2.5.1/maintaining/datastore.html?highlight=filter#ckanext.datastore.logic.action.datastore_delete
>>>> >>
>>>> >> Running the API with
>>>> >>
>>>> >> 'filters': {'_id': '0'}
>>>> >>
>>>> >> does work, but setting
>>>> >>
>>>> >> {'_id': '>0'}
>>>> >>
>>>> >> or
>>>> >>
>>>> >> {'_id': '*'} fails.
>>>> >>
>>>> >> How can I empty a table in the datastore without deleting the table?
>>>> >>
>>>> >> The SQL generated in CKAN is:
>>>> >>
>>>> >> ...9b89-7ab1c36c8e00" WHERE ("_id" = '*') ...
>>>> >>
>>>> >> So it make sense why it fails, but I don't know how to use the API
>>>> calls
>>>> >> with either wildcards or "higher than".
>>>> >>
>>>> >> _______________________________________________
>>>> >> ckan-dev mailing list
>>>> >> ckan-dev at lists.okfn.org
>>>> >> https://lists.okfn.org/mailman/listinfo/ckan-dev
>>>> >> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> >
>>>> > Vítor Baptista
>>>> >
>>>> > http://vitorbaptista.com
>>>> >
>>>> >
>>>> > _______________________________________________
>>>> > ckan-dev mailing list
>>>> > ckan-dev at lists.okfn.org
>>>> > https://lists.okfn.org/mailman/listinfo/ckan-dev
>>>> > Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>> >
>>>> _______________________________________________
>>>> ckan-dev mailing list
>>>> ckan-dev at lists.okfn.org
>>>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>>>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>>
>>>
>>>
>>> _______________________________________________
>>> ckan-dev mailing list
>>> ckan-dev at lists.okfn.org
>>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>>
>>>
>>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160224/3e36f8bf/attachment-0003.html>


More information about the ckan-dev mailing list