postgresql - 如何将时间戳转换为日期
问题描述
在一个视图中,我正在投射一个没有时区的时间戳。
在我看来,这些中的任何一个都应该起作用:
Cast("Orders"."OrderDate" as Date),
Date("Orders"."OrderDate"),
"Orders"."OrderDate"::Date,
但他们都给出了错误
cannot change data type of view column "OrderDate" from timestamp without time zone to date
Postgres 11
pgAdmin 4.9
解决方案
select date_trunc('day', now());
| 日期截断 | | :--------------------- | | 2019-08-31 00:00:00+01 |
select date_trunc('day', now())::date;
| 日期截断 | | :--------- | | 2019-08-31 |
db<>在这里摆弄
推荐阅读
- ios - 为什么将绑定注入 UIViewControllerRepresentable 会导致保留周期?
- rabbitmq - AMQP Elixir 库发出错误“未定义函数 'Elixir.AMQP.Application':get_channel(chan)”
- exception - 通过 urlfetchapp 发出请求会产生“异常:属性提供的值无效:标头:内容长度”
- ios - SwiftUI 中的 Firebase 初始化数据快照
- typescript - 如何使我的打字稿库对我的打字稿应用程序进行类型检查
- scala - 求火花流窗口函数的最小值和最大值
- python - 清除所有对象的某些字段的所有数据?
- java - Java 不兼容类型:子类无法转换为父类
- c++ - 如何通过 avx 对 int64 取模
- html - 如何使用 animate.css