code ที่เขียน
โค้ด: เลือกทั้งหมด
import psycopg2 as p
con = None
try:
con = p.connect(database="test_selenium", user="postgres")
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS test_01")
#Create table as per requirement
sql = """Create TABLE IF EXISTS test_01(
id serial Not NULL,
topic character varying(100) Not NULL,
sc character varying(100) Not NULL,
CONTRAINT test_pythons_pkey PRIMARY KEY (id)
)
"""
cur.execute(sql)
con.commite()
print("create_success")
except p.DatabaseError:
print('Error %s' %p.DatabaseError)
if con:
con.close()
โค้ด: เลือกทั้งหมด
/home/com003/PycharmProjects/pythonProject_selenium_test/venv/bin/python "/home/com003/PycharmProjects/pythonProject_selenium_test/create tabel.py"
Error <class 'psycopg2.DatabaseError'>
Process finished with exit code 0