Bugfix in the upload function

Merged from branch test_nuts
minor changes in the sql upsert