Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PostgreSQL guarantee unique timestamps?

8-byte integers are now the default for Postgres 8.4, so it allows microsecond values to be stored.

I don't care too much about real microsecond precision (probably depends on OS capabilities?!) - But does Postgres guarantee, that the timestamp values (inserted by current_timestamp) are always different between any two transactions?

like image 547
Chris Lercher Avatar asked Aug 09 '10 17:08

Chris Lercher


People also ask

How does Postgres store timestamps?

PostgreSQL stores the timestamptz in UTC value. When you insert a value into a timestamptz column, PostgreSQL converts the timestamptz value into a UTC value and stores the UTC value in the table.

Does Postgres support timestamp?

PostgreSQL supports the full set of SQL date and time types, shown in Table 8.9.

What is the default timestamp PostgreSQL?

#Example 1 In PostgreSQL, a column's current timestamp is used as the default value, and the current timestamp and time are used to deliver values with the time zone. The current statement's start time is the time of the most recent command received from you.


2 Answers

No.

I did a small test, inserting current_timestamp from 5 parallell clients in a table, 3 of 3463 records got the same timestamp.

like image 55
nos Avatar answered Sep 22 '22 07:09

nos


Yes, precision depends on the OS. Within a single transaction the timestamps are all the same when using CURRENT_TIMESTAMP, when using CLOCK_TIMESTAMP they might be different. Different transactions can have different CURRENT_TIMESTAMPS, depends on how fast you can insert/update.

If you need uniqueness, add a unique constraint.

like image 22
Frank Heikens Avatar answered Sep 25 '22 07:09

Frank Heikens