psycopg2、SELECT 和模式

发布于 2024-10-14 14:20:57 字数 654 浏览 2 评论 0原文

我正在尝试在属于“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-10-21 14:20:57

双引号使其中的内容成为标识符,因此查询

SELECT * FROM "dam_vector.parcels_full";

会从schama public(或搜索路径中的任何内容)命中表dam_vector.parcels_full(句点解释为表名称的一部分) 。

正如 Adam 所说,您不需要对不带特殊字符的名称进行引号。
尝试:

SELECT * FROM dam_vector.parcels_full;

如果您确实想使用双引号,请执行以下操作:

SELECT * FROM "dam_vector"."parcels_full";

Double quotes makes whatever is in them an identifier, so query

SELECT * FROM "dam_vector.parcels_full";

hits table dam_vector.parcels_full (period interpreted as part of table name) from schama public (or anything in search path).

As Adam said, you don't need quotes with names without some special characters.
Try:

SELECT * FROM dam_vector.parcels_full;

If you really want to use a double quotes, go for:

SELECT * FROM "dam_vector"."parcels_full";
纵情客 2024-10-21 14:20:57

您不需要在 dam_vector.parcels_full 周围加上引号。

以下输出是否表明 parcels_full 表确实存在?

cur.execute("""SELECT tablename 
                 FROM pg_tables 
                WHERE tablename NOT LIKE ALL (ARRAY['pg_%','sql_%']);""")
cur.fetchall()

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?

cur.execute("""SELECT tablename 
                 FROM pg_tables 
                WHERE tablename NOT LIKE ALL (ARRAY['pg_%','sql_%']);""")
cur.fetchall()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文