【发布时间】:2021-11-24 23:56:12
【问题描述】:
我正在尝试从数据库中删除一个表。
只要name_Table 的结构为
schema.table
这一切都很好。但是,我在public 架构中确实有一张表。
当我尝试将其删除为:
public.subname.table
我得到这个答案:
cross-database references are not implemented: "public.subname.table"
如何删除public.subname.table?
print('Connecting to the PostgreSQL database...')
postgresConnection = psycopg2.connect(
host=XXXXXX,
port=YYYYYYYYY,
database="mydb",
user=os.environ['user'],
password=os.environ['pwd'])
cursor = postgresConnection.cursor()
dropTableStmt = "drop TABLE %s;"%name_Table;
# Create a table in PostgreSQL database
print(dropTableStmt)
cursor.execute(dropTableStmt)
postgresConnection.commit()
cursor.close();
print('Database cursor closed.')
postgresConnection.close()
print('Database connection closed.')
【问题讨论】:
-
没有
public.subname.table这样的东西。有一个public模式,其中可以有表,所以你可以有public.table。同样出于Parameters 此处显示的原因,您不想使用 `dropTableStmt = "drop TABLE %s;"%name_Table;`。 -
好的。但是我在公共场合的桌子上有一个点,例如public.subname.name.how 删除那些?如果我只是删除 subname.name,我会在原始问题中得到错误
-
那是个坏主意。您现在必须引用名称。最好的方法是
drop TABLE quote_ident(%s)。然后花点时间在这里Identifiers 为您解决更多问题。 -
你能回答吗?
标签: sql pandas postgresql schema psycopg2