Python 使用dict在SQL insert上设置浮点格式

Python 使用dict在SQL insert上设置浮点格式,python,sql,dictionary,sql-insert,postgresql-9.5,Python,Sql,Dictionary,Sql Insert,Postgresql 9.5,我尝试通过SQLINSERT语句将字典中的值插入postgres数据库 宿主语言是Python 首先,我只使用VARCHAR Datytype并像这样转换值 insert_query = 'INSERT INTO tweets VALUES (%s, %s)' for tweet in tweets: engine.execute(insert_query, (tweet['username'], tweet['text']) 在下一步中,我还需要“追随者数量”(如2

我尝试通过SQLINSERT语句将字典中的值插入postgres数据库

宿主语言是Python

首先,我只使用VARCHAR Datytype并像这样转换值

insert_query = 'INSERT INTO tweets VALUES (%s, %s)'
    for tweet in tweets:
        engine.execute(insert_query, (tweet['username'], tweet['text']) 
在下一步中,我还需要“追随者数量”(如2345)和“情绪分数”(如0.654)的数值

是否有类似于%f(转换为浮点)的方法或其他方法可以正确执行此操作?

尝试以下方法:

insert_query = 'INSERT INTO tweets VALUES (%s, %s, %f, %.2f)'
for tweet in tweets:
    engine.execute(insert_query, (tweet['username'], tweet['text'], tweet['floatval'], tweet['double_decimal_floatval']) 

在insert语句中尝试
%f
,或像
%.2f