【问题标题】:Display a day of week in text in postgresql在 postgresql 中以文本形式显示星期几
【发布时间】:2023-01-17 23:05:37
【问题描述】:

此查询显示按星期几分组的计数操作。

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

天数显示为数字。有没有办法将其显示为文本? PostgreSQL 有这样的功能吗?

【问题讨论】:

  • 可以试试select count(*) c, to_char(date_trunc('day', "updatedAt" at time zone 'Europe/Paris'), 'Day') dow
  • 使用 to_char() 和您喜欢的布局。通常这是在应用程序的表示层中完成的,而不是在数据库中

标签: sql postgresql


【解决方案1】:

如果你想要文本格式,请在末尾使用::TEXT。将来您可以使用其他类似::DATE::TIMESTAMP::DECIMAL...

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2020-10-23
    相关资源
    最近更新 更多