1.sql语句 [postgres@eulersvr ~]$ cat query.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;"""
cursor.execute(sql)
row=cursor.fetchone()
print (row)
conn.commit()
cursor.close()
conn.close()
2.执行SQL
[postgres@eulersvr ~]$ python3 query.py
(1, 100, 'mahan')
[postgres@eulersvr ~]$
|