简体   繁体   English

psycopg2 - UndefinedColumn:关系的列“日期时间”“<table_name> “ 不存在</table_name>

[英]psycopg2 - UndefinedColumn: column "datetime" of relation "<table_name>" does not exist

I'm getting this error message我收到此错误消息

UndefinedColumn: column "datetime" of relation "daily_price" does not exist
LINE 1: INSERT INTO public.daily_price (DateTime) VALUES ('200...
                                              ^

Code代码

cur.execute("INSERT INTO public.daily_price (DateTime) VALUES ('"+str(day)+"')");

How to deal with the reserved word column without altering it on the database?如何在不改变数据库的情况下处理保留字列?

As Tim Roberts points out, you have a different problem.正如蒂姆罗伯茨指出的那样,你有一个不同的问题。

Here is sample SQL that uses DateTime as a column name and executes successfully:这是使用 DateTime 作为列名并成功执行的示例 SQL:

CREATE TEMPORARY TABLE foo (DateTime timestamp);
INSERT INTO foo (DateTime) VALUES (now());

For completeness, here is what happens when you are truly using a reserved keyword that postgres objects to in context:为了完整起见,当您真正使用 postgres 在上下文中反对的保留关键字时,会发生以下情况:

CREATE TEMPORARY TABLE foo (select timestamp);
INSERT INTO foo (select) VALUES (now());

ERROR:  syntax error at or near "select"
LINE 1: CREATE TEMPORARY TABLE foo (select timestamp);
                                    ^
ERROR:  syntax error at or near "VALUES"
LINE 1: INSERT INTO foo (select) VALUES (now());

To fix this case, you would use double-quotes:要解决这种情况,您可以使用双引号:

CREATE TEMPORARY TABLE foo ("select" timestamp);
INSERT INTO foo ("select") VALUES (now());

This would work correctly - but this is not your problem.这将正常工作 - 但这不是你的问题。 Something you are not seeing is wrong with the schema.您没有看到的东西是架构错误的。

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

相关问题 (psycopg2.errors.UndefinedColumn) 列“名称”不存在 - (psycopg2.errors.UndefinedColumn) column "name" does not exist 在psycopg2中将表名作为参数传递时,公共表不存在关系 - Passing table name as a parameter in psycopg2, relation does not exist for a public table Django:psycopg2.errors.UndefinedColumn:“pages_page”关系的“page_image”列不存在 - Django: psycopg2.errors.UndefinedColumn: column “page_image” of “pages_page” relation does not exist ProgrammingError:(psycopg2.errors.UndefinedColumn)关系“task_fail”的列“execution_date”不存在 - ProgrammingError: (psycopg2.errors.UndefinedColumn) column "execution_date" of relation "task_fail" does not exist Psycopg2 关系数据库不存在 - Psycopg2 relation db does not exist psycopg2 - Postgresql 数据库中的“关系不存在” - psycopg2 - 'Relation does not exist' in Postgresql database 测试PostgreSQL表是否不存在(使用psycopg2) - Test if PostgreSQL table does NOT exist (with psycopg2) Odoo 10.0中的“ Many2many关系”中不存在关系“ table_name” - A relation “table_name” does not exist in “Many2many relation” in Odoo 10.0 Flask-SQLAlchemy 关系错误(关系“table_name”不存在) - Flask-SQLAlchemy relationship error (relation "table_name" does not exist) psycopg2 传入表名 - psycopg2 passing in table name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM