Difference between current_timestamp, now() and clock_timestamp() in postgresql

There are multiple methods to detect the current time in postgresql. Two of those methods are:

  1. Use the value current_timestamp
  2. Use the function now()
  3. Use the function clock_time()
INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , current_timestamp);
INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , now());
INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , clock_timestamp());

While all of these will insert a timestamp they work a little bit different.

  1. The first is a value defined in Standard SQL, you can find more standard values in the postgresql manual.
  2. The second and third are both postgresql functions The major difference is now() is adding the time at the beginning of the transactions, while, clock_timestamp() insert the time at the execution of the statement.

Wir freuen uns Sie kennen zu lernen

Hat Sie unser Angebot überzeugt? Dann freuen wir uns, Sie kennen zu lernen. Kontaktieren Sie uns gerne für ein unverbindliches Erstgespräch.

newcubator GmbH
Freie-Vogel-Straße 369
44269 Dortmund
dortmund@newcubator.com
+49 231/586 873 80
newcubator GmbH
Bödekerstraße 22
30161 Hannover
hannover@newcubator.com
+49 511/957 313 00