我正在尝试使用postgresql
和psycopg2
将新行插入flask
数据库中。
这是代码:
con = psycopg2.connect("host=localhost dbname=crm_whatsapp user=user_name password=user_password")
cur = con.cursor()
create = cur.execute("INSERT INTO crm_user_chat_data (number) VALUES (%s) returning id",(user_number,)) //Here it returns none
con.commit()
但是我得到的是None
而不是id
。
我该如何解决?
答案 0 :(得分:0)
您需要从游标中获取()获取ID:
cur = con.cursor()
create = cur.execute("INSERT INTO crm_user_chat_data (number) VALUES (%s) returning id",(user_number,))
con.commit()
insertId = cur.fetchone()