psycopg2、SELECT 和模式
我正在尝试在属于“dam_vector”模式的表上执行一个简单的选择语句。我得到的错误是:
psycopg2.ProgrammingError:关系 “dam_vector.parcels_full”不 存在第 1 行:选择 * FROM “dam_vector.parcels_full”
我无法弄清楚这一点,并且知道我错过了一些明显的东西。您能提供的任何帮助都会很棒。
这是我正在使用的代码。 db 是成功连接数据库的连接字符串。
cur = db.cursor()
query = 'SELECT * FROM "dam_vector.parcels_full"'
cur.execute(query)
results = cur.fetchall()
当失败时,在我在谷歌上做了一些研究后,我尝试了这个。同样的错误。
cur.execute("SET search_path TO dam_vector,public")
db.commit()
cur = db.cursor()
query = 'SELECT * FROM "parcels_full"'
cur.execute(query)
results = cur.fetchall()
I'm trying to do a simple select statement on a table that's part of the "dam_vector" schema. The error I get is:
psycopg2.ProgrammingError: relation
"dam_vector.parcels_full" does not
exist LINE 1: SELECT * FROM
"dam_vector.parcels_full"
I can't figure this out and know I'm missing something obvious. Any help you can provide would be great.
Here's the code I'm using. db is a connection string that successfully connects to the database.
cur = db.cursor()
query = 'SELECT * FROM "dam_vector.parcels_full"'
cur.execute(query)
results = cur.fetchall()
and when that failed and after I did some research on Google I tried this. Same error.
cur.execute("SET search_path TO dam_vector,public")
db.commit()
cur = db.cursor()
query = 'SELECT * FROM "parcels_full"'
cur.execute(query)
results = cur.fetchall()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
双引号使其中的内容成为标识符,因此查询
会从schama
public
(或搜索路径中的任何内容)命中表dam_vector.parcels_full
(句点解释为表名称的一部分) 。正如 Adam 所说,您不需要对不带特殊字符的名称进行引号。
尝试:
如果您确实想使用双引号,请执行以下操作:
Double quotes makes whatever is in them an identifier, so query
hits table
dam_vector.parcels_full
(period interpreted as part of table name) from schamapublic
(or anything in search path).As Adam said, you don't need quotes with names without some special characters.
Try:
If you really want to use a double quotes, go for:
您不需要在
dam_vector.parcels_full
周围加上引号。以下输出是否表明
parcels_full
表确实存在?You shouldn't need the quotes around
dam_vector.parcels_full
.Does the output of the following show that a
parcels_full
table is indeed present?