skip to Main Content

This query displays count Actions grouped by day of the week.

select count(*) c, 
date_part('dow', "updatedAt"  at time zone 'Europe/Paris') dow
from "Action" date_part('dow', "updatedAt"  at time zone 'Europe/Paris')

Days are displayed as number. Is there a way to display it as text? Does PostgreSQL has such a function?

2

Answers


  1. IF you want text format use ::TEXT at the end. in future you can use other like ::DATE, ::TIMESTAMP, ::DECIMAL

    date_part('dow', "updatedAt" at time zone 'Europe/Paris')::TEXT dow

    Login or Signup to reply.
  2. Use to_char() to format a date or timestamp value as text. You can use Day to display the day’s name (e.g. Tuesday)

    select count(*) c, 
           to_char("updatedAt"  at time zone 'Europe/Paris', 'Day') dow
    from "Action" 
    group by to_char("updatedAt"  at time zone 'Europe/Paris', 'Day')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search