gpt4 book ai didi

python - 如何按月份名称查询sqlalchemy

转载 作者:太空宇宙 更新时间:2023-11-04 01:25:16 26 4
gpt4 key购买 nike

我试过了

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()

最佳答案

您想调用 PostgresSQL 函数 to_char , 而不是 Python datetime 函数 strftime:

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

关于python - 如何按月份名称查询sqlalchemy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18265443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com