Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store timestamp value upto only 3 millisecond digit in PostgreSQL

I have to store upto 3 millisecond digit in timestamp column.
I have two fixed column in each tables: createdDate,LastmodifiedDate.
While inserting data value of CreatedDate/LastmodifiedDate:

now() at time zone 'utc'

But it is storing 5 digit of millisecond.
I would like to store only 3 fractional digit of millisecond.
let me suggest which type of datatype is storing only 3 fractional digit of millisecond.
let me know if you have any solution.

like image 628
Nayan Rudani Avatar asked Sep 17 '25 15:09

Nayan Rudani


1 Answers

Postgres allows you to specify precision(0 to 6) while casting to TIMESTAMP

See Docs

So, you could do

select (now() at time zone 'utc') :: timestamp(3)

Demo

like image 130
Kaushik Nayak Avatar answered Sep 19 '25 08:09

Kaushik Nayak