【发布时间】:2016-10-04 21:39:33
【问题描述】:
我有一个 sql 命令,只想在某些条件下选择一些记录(使用 python & db 是 Postres): 所以,我的查询是:
current_date= datetime.now()
tt = yield self.db.execute(self.db.execute('SELECT "Id", "RubricId", "IsRubric"
FROM whis2011."CoockieUserInterests"
'WHERE "UserId" = %s AND "Date" = %s '
% (Id, current_date))
result=tt.fetchall()[0]
问题:当我想将日期时间传递给“日期”字段时出现错误:
syntax error at or near "00"
LINE 1: ...rests" WHERE "UserId" = 1 AND "Date" = 2016-10-05 00:22:07.3...
^
数据库中的所有“日期”字段都类似于:2016-09-25 00:00:00
另外,数据库中“日期”字段的数据类型是“没有时区的时间戳”。
这是我的游泳池:
application.db = momoko.Pool(
dsn='dbname=xxxx user=xxxxx password=xxxxx host=xxxx port=5432',
size=1,
ioloop=ioloop,
)
如何在我的数据库中选择具有这种格式的“日期”?
【问题讨论】:
-
您容易受到sql injection attacks 的攻击。您需要阅读此问答:stackoverflow.com/questions/10950362/…
标签: python postgresql datetime