1.语句
[postgres@eulersvr ~]$ cat update.py
# _*_ coding:utf-8 _*_
import psycopg2
conn= psycopg2.connect(database="postgres",user="postgres",password="postgres",host="192.168.0.38",port="5432")
cursor=conn.cursor()
sql="""update emp set last_name=%s where empno=%s;"""
params=('libai',100)
cursor.execute(sql,params)
conn.commit()
cursor.close()
conn.close()
2.执行
[postgres@eulersvr ~]$ python3 update.py
3.验证
[postgres@eulersvr ~]$ psql
psql (16.1)
Type "help" for help.
postgres=# select * from emp where empno=100;
id | empno | last_name
----+-------+-----------
1 | 100 | libai
(1 row)
postgres=#
|