0
我有一個LocationEvent
模型,它具有timestamp
屬性,它是DateTime
字段。我想寫一個函數,它將採用start_time
和end_time
(它們是python time
對象),並將返回在這兩個時間之間的對象 - 無論日期如何。使用SqlAlchemy + python在日期時間字段上按時過濾
我嘗試使用SQLAlchemy中的extract
函數,但無法成功。我嘗試以下 -
LocationEvent.query.filter(sqlalchemy.extract('time', LocationEvent.timestamp) >= start_time)
這給了我下面的錯誤 -
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near 'time FROM location_event.timestamp) >= '08:00:00'' at line 3") 'SELECT
location_event.id AS location_event_id, location_event.latitude AS location_event_latitude,
location_event.longitude AS location_event_longitude, location_event.type AS
location_event_type, location_event.timestamp AS location_event_timestamp,
location_event.creation_date AS location_event_creation_date \nFROM location_event \nWHERE
EXTRACT(time FROM location_event.timestamp) >= %s' ('08:00:00',)
我如何能做到這一點任何想法?
'EXTRACT'不是由SQL Server的支持。 – zsong