Consider the structure of table field 'extra' is as follows:
extra = sql.Column(sql.JsonBlob())
So it is of JsonBlob type.
Now I need to update some values in to the field 'extra'.
When I am trying to update the 'extra' value, it ends up in error which is as follows:
File "basic_test.py", line 38
sql = "update project set extra=('{"creation_date": "%s"}') where id=('%s')" % (date, tenant_id)
^
SyntaxError: invalid syntax
Code I have tried is as follows:
import datetime
mylist = []
today = datetime.date.today()
mylist.append(today)
date = mylist[0]
tenant_id = '1578f81703ec4bbaa1d548532c922ab9'
sql = "update project set extra='{"creation_date": "%s"}' where id=('%s')" % (date, tenant_id)
cur.execute(sql)
Note:
For example, I am providing here the same type of data used in another table.
I have selected the rows from the table and providing the sample here.
('{"email": "test@example.com"}',)
<type 'tuple'>
So this is the type of data which is being stored in extra field.
Some one have a look and let me know your comments.
Let me know If it needs more Information.
Thanks in advance.
答案 0 :(得分:0)
I found the answer myself.
extra = '{"creation_date": "%s"}' % date
sql = "update project set extra=('%s') where id=('%s')" % (extra, tenant_id)
Changed the query as above so that I can be able to see that DB table is getting updated as needed correctly.