[ckan-dev] Empty datastore table in CKAN

Ian Ward ian at excess.org
Wed Feb 24 14:06:19 UTC 2016


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
>



More information about the ckan-dev mailing list