python连接PostgreSql增删改查操作代码
代码语言:python
所属分类:其他
代码描述:python连接PostgreSql增删改查操作代码
代码标签: python 连接 PostgreSql 增删改查 操作 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* import psycopg2 conn = psycopg2.connect(database="test_db", user="test_user", password="abc123", host="127.0.0.1", port="5432") print("Opened database successfully") # cur = conn.cursor() # cur.execute('''CREATE TABLE COMPANY # (ID INT PRIMARY KEY NOT NULL, # NAME TEXT NOT NULL, # AGE INT NOT NULL, # ADDRESS CHAR(50), # SALARY REAL);''') # print("Table created successfully") # conn.commit() # conn.close() # cur = conn.cursor() # cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \ # VALUES (1, 'Paul', 32, 'California', 20000.00 )"); # cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \ # VALUES (2, 'Allen', 25, 'Texas', 15000.00 )"); # cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \ # VALUES (3, 'Teddy', 23, 'Norway', 20000.00 )"); # cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \ # VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 )"); # conn.commit() # print("Records created successfully"); cur = conn.cursor() cur.execute("SELECT id, name, address, salary from COMPANY&.........完整代码请登录后点击上方下载按钮下载查看
网友评论0