[英]drop postgreSQL table with Quotation Marks in name using psycopg2
I have a table in a schema.我在模式中有一个表。
my_schema.my_table
In the same schema, I also have a table named the same but with quotation marks在同一个模式中,我还有一个名称相同但带有引号的表
my_schema."my_table"
How can I drop my_schema."my_table"
using psycopg2?如何使用 psycopg2 删除my_schema."my_table"
? (without risking to drop my_schema.my_table
) (不要冒险放弃my_schema.my_table
)
I have tried:我努力了:
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();
But I get但我明白了
SyntaxError: zero-length delimited identifier at or near """"
LINE 1: drop TABLE my_schema.""my_table"";
I have also tried:我也试过:
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();
But then I get:但后来我得到:
UndefinedTable: table "my_schema.""my_table""" does not exist
To escape double quotes in an object name, double the double quotes:要在 object 名称中转义双引号,请将双引号加倍:
DROP TABLE my_schema."""my_table""";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.