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:
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.