【问题标题】:Timestamp with time zone, unknown using django ORM带有时区的时间戳,使用 django ORM 未知
【发布时间】:2019-01-11 08:24:28
【问题描述】:

从 MariaDB 转移到 postgres-10 后,我遇到了错误 我正在使用 Django-orm

function date_format(timestamp with time zone, unknown) 不存在 第 1 行:SELECT (DATE_FORMAT(created_at,'%h %p')) AS "in_hours", SUM(...

提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。

Model.objects.filter(franchise=franchise)\
             .filter(created_at__date=date)\
             .extra(select={'in_hours': "DATE_FORMAT(created_at,'%%h %%p')"}) \
             .values('in_hours')\
             .order_by('created_at__hour')\
             .annotate(total_amount=Sum('amount'))

谁能解释一下哪里出错了。 谢谢

【问题讨论】:

    标签: python django postgresql django-orm


    【解决方案1】:

    Postgres中没有DATE_FORMAT函数,必须使用TO_CHAR https://www.postgresql.org/docs/9.1/functions-formatting.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-24
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多