Python 3.x 如何在postgres表中使用Python条件语句
如何在postgres表中使用Python条件语句 如果表存在,则打印已创建的表 如果它不存在,它将被描述为不存在 我的代码:Python 3.x 如何在postgres表中使用Python条件语句,python-3.x,postgresql,Python 3.x,Postgresql,如何在postgres表中使用Python条件语句 如果表存在,则打印已创建的表 如果它不存在,它将被描述为不存在 我的代码: import psycopg2 from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT conn_string = "host='localhost' dbname='wooow' user='postgres' password='root'" conn = psycopg2.conn
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
conn_string = "host='localhost' dbname='wooow' user='postgres' password='root'"
conn = psycopg2.connect(conn_string)
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
print("Database Coonected successfully")
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS bobo(id serial PRIMARY KEY, sname CHAR(50), roll_num
integer);")
if True:
print("Table Created")
if False:
print("Table EXISTS")
conn.commit()
conn.close()
print("Database DeCoonected successfully")
这回答了你的问题吗?