Nayan Rudani
Nayan Rudani

Reputation: 1189

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.

Upvotes: 4

Views: 6688

Answers (1)

Kaushik Nayak
Kaushik Nayak

Reputation: 31666

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

Upvotes: 8

Related Questions