将时间戳变量纳入PostgreSQL Update语句

发布于 2025-01-31 10:30:04 字数 450 浏览 1 评论 0原文

我有以下代码段。它应该在我的PostgreSQL数据库中更新一排数据。我遇到的问题是,按照典型的时间戳格式(这给出语法错误),时间戳在日期和时间之间具有空间。如果我不想合并变量变量,我知道我将能够将其包装在“”中并将其称为“一天”。如何使用合并变量的括号方法完成?

cursor.execute("UPDATE {} SET timestamp = {}, ememctotal = {}, busload = {}, dgload = {}, temp = {}, cvr = {} WHERE (year = {} AND month = {});".format(histTable, mTimestamp, mPeak, mBusLoad, mdgLoad, mTemp, mstatus, histYear, histMonth))
print ("Historical Peak Data update complete")

I have the following snippet of code. It's supposed to update a row of data in my postgresql database. The issue I am running into is that the timestamp has a space between the date and time, following a typical timestamp format (which is giving a syntax error). If I weren't trying to incorporate a changing variable, I understand that I'd be able to just wrap it in " " and call it a day. How is it done using the bracket method of incorporating variables?

cursor.execute("UPDATE {} SET timestamp = {}, ememctotal = {}, busload = {}, dgload = {}, temp = {}, cvr = {} WHERE (year = {} AND month = {});".format(histTable, mTimestamp, mPeak, mBusLoad, mdgLoad, mTemp, mstatus, histYear, histMonth))
print ("Historical Peak Data update complete")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文