我在模式中有一个表。
my_schema.my_table
在相同的模式中,我还有一个名为相同但带有引号的表
my_schema."my_table"
我怎么能放弃
my_schema."my_table"
使用psycopg2?
(不冒摔下去的风险
my_schema.my_table
)
postgresConnection = psycopg2.connect(...)
from psycopg2 import sql
cursor = postgresConnection.cursor()
name_Table = 'my_schema."my_table"'
cursor = postgresConnection.cursor()
dropTableStmt = "drop TABLE %s;"%name_Table;
cursor.execute(dropTableStmt)
postgresConnection.commit()
cursor.close();
但我明白了
SyntaxError: zero-length delimited identifier at or near """"
LINE 1: drop TABLE my_schema.""my_table"";
我也尝试过:
from psycopg2 import sql
cursor = postgresConnection.cursor()
name_Table = 'my_schema.""my_table""'
cur = postgresConnection.cursor()
cur.execute(sql.SQL("DROP table {table}").format(table=sql.Identifier(name_Table)))
postgresConnection.commit()
cursor.close();
但我得到:
UndefinedTable: table "my_schema.""my_table""" does not exist