Python mysql动态添加列并更新新列中的值 [英] Python mysql dynamic add column and update values in the new columns

查看:456
本文介绍了Python mysql动态添加列并更新新列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for i in onlycolumns:
if i not in pat and i not in ref:
    new=lister.index(i)
    value1 = lister[new+1]
    query="ALTER TABLE test add %s varchar(30)" %i
    cursor.execute(query)

    query1 = """ UPDATE test
           SET % = %s
            WHERE patient_name = %s """
    data = (i,value1,value)
    cursor.execute(query1, data)     

这些列是动态添加的,但其中的值不会更新...我的更新命令有任何错误。 .... value 变量是患者姓名的名称...是正确的, value1 中的值是'a'。请与我联系
使用更新命令

The columns are added dynamically but the values are not updated in it ...any wrong with my update command......value variable here is the name of patient name ...it is right and the value in value1 is 'a'.pLEASE HELP ME ANYONE WITH THE UPDATE COMMAND

推荐答案

问题出在SET上:使用
SET%s =%s。

The problema is with the SET: Use SET %s = %s.

您错过了接近1%的s。

You miss the the s near one %.

这篇关于Python mysql动态添加列并更新新列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆