如何按月份名称查询sqlalchemy

时间:2013-08-16 03:39:53

标签: python sqlalchemy flask flask-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()

1 个答案:

答案 0 :(得分:3)

您想要调用PostgresQL函数to_char,而不是Python datetime函数strftime

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