简体   繁体   English

Psycopg2 关系数据库不存在

[英]Psycopg2 relation db does not exist

I recently started using Macbook because my laptop was changed at work and right after that I started having problems with some of my code that I use to upload a dataframe to a postgresql database.我最近开始使用 Macbook,因为我的笔记本电脑在工作时发生了变化,之后我开始遇到一些用于将数据帧上传到 postgresql 数据库的代码的问题。

import psycopg2
from io import StringIO

def create_connection(user,password):
    return psycopg2.connect(
    host='HOST',
    database='DBNAME',
    user=user,
    password=password)

conn = create_connection(user,password)

table = "data_analytics.tbl_summary_wingmans_rt"
buffer = StringIO()
df.to_csv(buffer, header=False, index=False)
buffer.seek(0)
cursor = conn.cursor()
cursor.copy_from(buffer, table, sep=",", null="")
conn.commit()
cursor.close()

As you can see, the code is quite simple and even before the change of equipment it ran without major problem on Windows.如您所见,代码非常简单,即使在更换设备之前,它在 Windows 上也没有出现重大问题。 But as soon as I run this same code on the mac it throws me the following error:但是一旦我在 mac 上运行相同的代码,它就会抛出以下错误:

Error: relation "data_analytics.tbl_summary_wingmans_rt" does not exist

In several posts I saw that it could be the use of double quotes but I have already used the following and I still do not have a positive result.在几篇文章中,我看到可能使用了双引号,但我已经使用了以下内容,但仍然没有得到肯定的结果。

"data_analytics."tbl_summary_wingmans_rt""
""data_analytics"."tbl_summary_wingmans_rt""
'data_analytics."tbl_summary_wingmans_rt"'

The behaviour of copy_from changed in psycopg2 2.9 to properly quote the table name, which means that you can no longer supply a schema-qualified table name that way; copy_from的行为在 psycopg2 2.9 中更改为正确引用表名,这意味着您不能再以这种方式提供模式限定的表名; you have to use copy_expert instead.您必须改用copy_expert

You have to separate schema and table before sending it to Postgres parser now, when you are sending "data_analytics.tbl_summary_wingmans_rt" its a single string and unable to parse现在,当您发送"data_analytics.tbl_summary_wingmans_rt"它是一个字符串并且无法解析时,您必须在将其发送到 Postgres 解析器之前将模式和表分开

use '"data_analytics"."tbl_summary_wingmans_rt"' this will parse the output as "schema"."table" and PostgreSQL will be able to parse使用'"data_analytics"."tbl_summary_wingmans_rt"'这会将输出解析为 "schema"."table" 并且 PostgreSQL 将能够解析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 psycopg2 - Postgresql 数据库中的“关系不存在” - psycopg2 - 'Relation does not exist' in Postgresql database ProgrammingError:安装Psycopg2后关系“django_session”不存在错误 - ProgrammingError: relation “django_session” does not exist error after installing Psycopg2 在psycopg2中将表名作为参数传递时,公共表不存在关系 - Passing table name as a parameter in psycopg2, relation does not exist for a public table psycopg2 - UndefinedColumn:关系的列“日期时间”“<table_name> “ 不存在</table_name> - psycopg2 - UndefinedColumn: column "datetime" of relation "<table_name>" does not exist Postgresql&psycopg2:数据库不存在 - Postgresql & psycopg2: database does not exist psycopg2 OperationalError: 游标不存在 - psycopg2 OperationalError: cursor does not exist 测试PostgreSQL表是否不存在(使用psycopg2) - Test if PostgreSQL table does NOT exist (with psycopg2) psycopg2.ProgrammingError:关系“匹配”不存在 - psycopg2.ProgrammingError: relation “matches” does not exist python psycopg2-ProgrammingError:函数交叉表(未知,未知)不存在 - python psycopg2 - ProgrammingError: function crosstab(unknown, unknown) does not exist Psycopg2“运算符不存在:整数[] =整数”错误 - Psycopg2 “operator does not exist: integer[] = integer” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM