[postgres@eulersvr ~]$ cat query_cond.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="""select * from emp where empno=%s;"""
params=(100,)
cursor.execute(sql,params)
rows=cursor.fetchall()
print (rows)
conn.commit()
cursor.close()
conn.close()
2.执行
[postgres@eulersvr ~]$ python3 query_cond.py
[(1, 100, 'mahan')]
|