1.语句
[postgres@eulersvr ~]$ cat delete.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="""delete from emp where empno=%s; """
params=(100,)
cursor.execute(sql,params)
conn.commit()
cursor.close()
conn.close()
[postgres@eulersvr ~]$
2.执行
[postgres@eulersvr ~]$ python3 delete.py
3.验证
[postgres@eulersvr ~]$ psql
psql (16.1)
Type "help" for help.
postgres=# select * from emp;
id | empno | last_name
----+-------+-----------
2 | 101 | liuzy
3 | 102 | wangj
100这条记录已经没有了
|