[英]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.