I've put the batch update here:
http://gist.github.com/277373
After much testing, it now works, as far as I can tell. It broadly follows this procedure:
1. Load a CSV into a temp table.
2. Prepare the static variables that will be used for all of the new determinations.
3. Create a cursor that contains a list of taxon_occurrence_keys to add new determinations to. The names in the CSV temp table are used to find the keys.
4. Iterate over each taxon_occurrence_key in the cursor creating a new determination for each and pointing the taxon occurrence to the new determination (i.e., make the new determination preferred)
The workflow behind this update is as follows:
We extracted all of the data we hold for a list of 'scarce' moths as defined by our county recorder for moths. He went through these data and marked ones he thought were incorrect, suspect or completely wrong. We then added the appropriate determinations by hand to these suspect records, the 'completely wrong' ones were marked as invalid rather than being deleted.
So the batch update take the list of scarce moths we provided and adds 'considered correct' determinations to all records that have not been determined otherwise by the county recorder. All records that have an 'Invalid' determination, whether by the county recorder or not, will be ignored.
The whole thing should probably be wrapped in a transaction in case anything goes wrong during the query. I'll add that next, perhaps.
If I've understood your scenario correctly, Richard, you're trying to do exactly the same thing only against a list of taxon_occurrence_keys, rather than a list of taxon names. This actually makes the update a little bit simpler: you just need to alter the cursor declaration a little bit. Here's a revised version of the update that should operate on a CSV that contains a list of taxon_occurrence_keys instead of a list of species names:
http://gist.github.com/277413
I've not tested this one, though, so I don't know if it'll work!
I should finish this by saying a BIG thank you to Mike Weideli without whose help I wouldn't have been able to do this. Cheers, Mike!
Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital