Muhammad Saqib
Muhammad Saqib

Reputation: 121

Timestamp with time zone, unknown using django ORM

After shifting from MariaDB to postgres-10 i am getting below error I am using Django-orm

function date_format(timestamp with time zone, unknown) does not exist LINE 1: SELECT (DATE_FORMAT(created_at,'%h %p')) AS "in_hours", SUM(...

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

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

Can anyone please explain where its going wrong. Thank you

Upvotes: 1

Views: 1740

Answers (1)

Dorofeev Andrey
Dorofeev Andrey

Reputation: 156

There is no DATE_FORMAT function in Postgres, you must use TO_CHAR https://www.postgresql.org/docs/9.1/functions-formatting.html

Upvotes: 3

Related Questions