2013-08-16 88 views
2

查詢SQLAlchemy的我想這如何通過月份名稱

db_session.query(PaymentsMade).filter(func.strftime('%B', PaymentsMade.created_at) == "August").all() 

,但我得到這個錯誤

(ProgrammingError) function strftime(unknown, timestamp without time zone) does not exist 
LINE 3: WHERE strftime('%B', paymentsmade.created_at) = 'August' 
     ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 

和現在的儲蓄created_at = datetime.utcnow()

+0

您使用的數據庫是? –

+0

** postgres **謝謝你的回覆 – sunny

回答

3

你要撥打的PostgreSQL的功能定位日期to_char ,而不是Python datetime函數strftime

db_session.query(PaymentsMade) \ 
    .filter(func.to_char(PaymentsMade.created_at, "FMMonth") == "August") 
+0

完美:)如何查詢月份列表前「六月,七月,八月」 – sunny

+0

@sunny - 你應該能夠改變')==「八月」' ').in _(「六月」,「七月」,「八月」)'並且有效(但我不是100%確定的)。 –

+0

耶工作正常:D – sunny