jeudi 17 septembre 2015

Python SQLite3 generating random number per row

I'm writing a python script which requires some work with an SQLite database. I'm copying values from another_table to table_of_numbers and attempting to generate a random number between 0-100 for each row in the table_of_numbers table. Here's my code:

  cursor.execute('CREATE TABLE  table_of_numbers (id, value1, value2, random_number)')

  cursor.execute('INSERT INTO table_of_numbers (id, value1, value2) SELECT id, value1, value2 FROM another_table')

  cursor.execute('UPDATE table_of_numbers SET random_number = abs(checksum(NewId()) % 100) WHERE  random_number IS NULL')

However, I'm getting this error: OperationalError: no such function: NewId

Can anyone spot my mistake? Thankyou

Aucun commentaire:

Enregistrer un commentaire