Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL support for timestamps to nanosecond resolution

Tags:

postgresql

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?

like image 954
user1005909 Avatar asked Jan 06 '17 20:01

user1005909


2 Answers

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.

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

like image 69
fvannee Avatar answered Sep 23 '22 16:09

fvannee


Nope, but you could trim timestamps to milliseconds, and store nanosecond part to a separate column. You can create index on both, and view or function to return your wanted nanosecond timestamp, and you can even create index on your function.

like image 31
jalmasi Avatar answered Sep 20 '22 16:09

jalmasi