0

I want to update a field blob in a existing database but it raises me an error.

execute("UPDATE table_name SET blob_column={} WHERE var1=1 AND var2=2".format(b"\x01\x02")))

I want to replace the actual data on the blob_column with \x01\x02 instead. This error occurs :

error : near "'\x01\x02'": syntax error (UPDATE table_name SET blob_column=b'\x01\x02' WHERE var1=1 AND var2=2)

Found this topic but don't understand : syntax to UPDATE a BLOB field in an existing SQLite record?

Biopy
  • 167
  • 1
  • 5
  • 15

1 Answers1

0

The syntax for the blob value should be x'0102' not b'\x01\x02' as per

UPDATE table_name SET blob_column= x'0102' WHERE var1=1 AND var2=2

The value being hexadecimal e.g. x'aaff'.

Each pair of characters is a byte so x'0102' is a blob that is two bytes in length.

MikeT
  • 51,415
  • 16
  • 49
  • 68