PostgreSQL 支持时间戳到纳秒分辨率 [英] PostgreSQL support for timestamps to nanosecond resolution

查看:58
本文介绍了PostgreSQL 支持时间戳到纳秒分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的数据具有低至纳秒的时间戳(我们实际上很关心).有没有办法让 Postgres 时间戳达到纳秒?

The data I'm receiving has timestamps down to nanoseconds (which we actually care about). Is there a way for Postgres timestamps to go to nanoseconds?

推荐答案

正如其他人所指出的,Postgres 没有提供这种开箱即用的类型.但是,由于 Postgres 的开源特性,创建支持纳秒分辨率的扩展相对简单.不久前我遇到了类似的问题,并为 Postgres 创建了这个timestamp9扩展.

As others have pointed out, Postgres doesn't provide such type out of the box. However, it's relatively simple to create an extension that supports nanosecond resolution due to the open-source nature of Postgres. I faced similar issues a while ago and created this timestamp9 extension for Postgres.

它在内部将时间戳存储为 bigint,并将其定义为自 UNIX 纪元以来的纳秒数.它围绕它提供了一些方便的功能,可以轻松查看和操作时间戳.如果您能忍受这些时间戳的有限时间范围,即 1970 年和 2262 年之间,那么这是一个很好的解决方案.

It internally stores the timestamp as a bigint and defines it as the number of nanoseconds since the UNIX epoch. It provides some convenience functions around it that make it easy to view and manipulate the timestamps. If you can live with the limited time range that these timestamps can have, between the year 1970 and the year 2262, then this is a good solution.

免责声明:我是扩展程序的作者

Disclaimer: I'm the author of the extension

这篇关于PostgreSQL 支持时间戳到纳秒分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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