我在jupyter笔记本中使用psycopg2创建了一个表。 这已成功完成,但我没有收到任何错误。现在,我想在pgAdmin界面中查看该表,但是该表没有出现。为什么?
这是我编写的代码:
import psycopg2
from psycopg2 import Error
try:
connection = psycopg2.connect(user = "postgres",
password = "nadav256",
port = "5432",
database = "postgres")
cursor = connection.cursor()
create_table_query = '''CREATE TABLE demo2
(ID INT PRIMARY KEY,
TIME VARCHAR(50),
ACCABS REAL,
BARO REAL); '''
cursor.execute(create_table_query)
connection.commit()
print("Table created successfully in PostgreSQL ")
except (Exception, psycopg2.DatabaseError) as error :
print ("Error while creating PostgreSQL table", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
这是我得到的输出:
Table created successfully in PostgreSQL
PostgreSQL connection is closed