Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

python - Psycopg2 update not updating the table and also doesn't throw any errors

I'm trying to move some data from a table called 'postsig' to 'usersig' in python and here's the code I'm using

cur.execute("SELECT userid FROM usersig")
userid = cur.fetchall()
for i in userid:
    print(i[0])
    q = """SELECT mediaid FROM postsig WHERE OWNERID = %s"""
    data = (i[0],)
    cur.execute(q, data)
    mediaids = cur.fetchall()
    mediaids2 = []
    for i in mediaids:
        mediaids2.append(i[0])
    q2 = """UPDATE usersig SET mediaids = %s WHERE userid = %s"""
    data2 = (mediaids2,i[0], )
    cur.execute(q2, data2)
    conn.commit()
    break

in this particular piece of code

i[0] = 2716168368 

mediaids2 = [1956830874667839346, 1965242936024519648, 1914749430730816263, 1796363135701978130, 1758915034963881429, 1741263757667258253]

after I execute there are no errors but also the actual table doesn't get updated. Could someone please tell me what I'm doing wrong?

Thankyou!

question from:https://stackoverflow.com/questions/65942358/psycopg2-update-not-updating-the-table-and-also-doesnt-throw-any-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...