我有以下代码来获取今天的日期:
today = str(date.today()) //2019-01-07
我想从timestamp
列不像今天那样的数据库中获取所有记录。功能如下:
def get_vehicle_references():
conn = db_connection()
cur = conn.cursor()
s = "SELECT reference, reference_url FROM vehicles v WHERE (NOT EXISTS (select reference from daily_run_vehicle rv WHERE (handled = %s or (handled = %s and retries >= %s)) and DATE(rv.timestamp) <> %s AND reference = v.reference))"
cur.execute(s, (True, False, 5, today))
return cur.fetchall()
时间戳列采用以下格式:2019-01-07 11:10:18.491368
我想从vehicles
表中获取所有记录,而timestamp
表中的daily_run_vehicle
列不是今天。
但是此查询还为我提供了今天的记录。
有什么主意吗?
更新:
因此,我尝试投射它,查询如下:
s = "SELECT reference, reference_url, timestamp FROM vehicles v WHERE (NOT EXISTS (select reference from daily_run_vehicle rv WHERE (handled = %s or (handled = %s and retries >= %s)) AND rv.timestamp::date = %s AND reference = v.reference))"
cur.execute(s, (True, False, 5, today))
但是我仍然有同样的问题。