How to store timestamp with milliseconds in PostgreSQL?

I know this is an old question, but I had a similar problem.

You can use the timestamp(n) field, with n equals the number of digits of precision to store on the date (timestamp(3) would give you millisecond precision)

Example

CREATE TABLE date_test (datetime timestamp(3) with time zone);

insert into date_test values(to_timestamp(1525745241.879));

select EXTRACT(epoch FROM datetime) from date_test;

Note: in current versions of postgres timestamp is stored as an integer, so it does not incur in floating point rounding issues

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)