【发布时间】:2016-02-03 03:27:27
【问题描述】:
考虑表字段'extra'的结构如下:
extra = sql.Column(sql.JsonBlob())
所以它是 JsonBlob 类型的。
现在我需要在“额外”字段中更新一些值。
当我尝试更新 'extra' 值时,最终会出错,如下所示:
File "basic_test.py", line 38
sql = "update project set extra=('{"creation_date": "%s"}') where id=('%s')" % (date, tenant_id)
^
SyntaxError: invalid syntax
我试过的代码如下:
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)
注意:
例如,我在这里提供了与另一个表中使用的相同类型的数据。
我已从表中选择行并在此处提供示例。
('{"email": "test@example.com"}',)
<type 'tuple'>
所以这是存储在额外字段中的数据类型。
有人看看,让我知道你的cmets。
如果需要更多信息,请告诉我。
提前致谢。
【问题讨论】: