本帖最后由 郑全 于 2023-12-10 18:46 编辑
1.创建SQL
[postgres@eulersvr ~]$ cat create-table.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="""create table emp(
id serial4 primary key,
empno int4,
last_name varchar(25));"""
cursor.execute(sql)
print ("emp table created successfully")
conn.commit()
conn.close()
2.执行SQL
[postgres@eulersvr ~]$ python3 create-table.py
emp table created successfully
3.验证表成功创建
|