1.SQL语句
[postgres@eulersvr ~]$ cat insert-row.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="""insert into emp(empno,last_name) values(%s,%s)"""
params = (100,'mahan')
cursor.execute(sql,params)
print ("successfully")
conn.commit()
conn.close()
2.执行SQL
[postgres@eulersvr ~]$ python3 insert-row.py
successfully
3.验证
[postgres@eulersvr ~]$ psql
psql (16.1)
Type "help" for help.
postgres=# select * from emp;
id | empno | last_name
----+-------+-----------
1 | 100 | mahan
(1 row)
postgres=#
|