如何从Postgres中的查询中提取小时 [英] How to extract hour from query in postgres

查看:1840
本文介绍了如何从Postgres中的查询中提取小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有时间戳,我只想从中提取一个小时。我搜索并找到了提取功能,但无法用作查询。我是否需要先在varchar中转换时间戳,然后从中提取小时?
这是我的查询:

I have timestamp in my table and i want to extract only hour from it. I search and find a extract function but unable to use as a query. Do i need to convert first timestamp in varchar and then extract hour from it? Here is my query:

select extract(hour from timestamp '2001-02-16 20:38:40') // example

实际查询:

select extract(hour from timestamp observationtime) from smartvakt_device_report


推荐答案

以下方法应该起作用

select extract(hour from observationtime) from smartvakt_device_report

这篇关于如何从Postgres中的查询中提取小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆