[英]drop postgreSQL table with Quotation Marks in name using psycopg2
我在模式中有一个表。
my_schema.my_table
在同一个模式中,我还有一个名称相同但带有引号的表
my_schema."my_table"
如何使用 psycopg2 删除my_schema."my_table"
? (不要冒险放弃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
要在 object 名称中转义双引号,请将双引号加倍:
DROP TABLE my_schema."""my_table""";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.