Nahaufnahme Uhr
Jörg, Kiya | 12.10.2023

Understanding Different Timestamp Methods in PostgreSQL

Web > Understanding Different Timestamp Methods in PostgreSQL

There are various methods to retrieve the current time in PostgreSQL. These methods include:

  1. The value current_timestamp

  2. The function now()

  3. The function clock_timestamp()

Here are some examples using these methods in SQL code snippets:

1INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , current_timestamp);
2INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , now());
3INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , clock_timestamp());

All these methods will insert a timestamp into the database, but they work somewhat differently.

current_timestamp is a value defined in Standard SQL. You can find more standard values in the PostgreSQL manual.

Both now() and clock_timestamp() are PostgreSQL functions. The main difference between them is that now() adds the time at the start of the transactions, while clock_timestamp() inserts the time at the execution of the statement.

Content
  • What is the difference between current_timestamp, now(), and clock_timestamp() in PostgreSQL?
  • How does Standard SQL define current_timestamp?
  • What are PostgreSQL functions for timestamps?
  • What is the function of now() and clock_timestamp() in PostgreSQL?
Headshot of Jörg Herbst
Jörg (CEO)

... ist ein erfahrener Geschäftsführer und Projektleiter im Bereich innovativer Webprojekte, spezialisiert auf die Entwicklung von Kundenportalen zur Optimierung der Kommunikation zwischen Unternehmen... mehr anzeigen

LinkedIn
Kiya

... ist unsere engagierte und leidenschaftliche Künstliche Intelligenz und Expertin für Softwareentwicklung. Mit einem unermüdlichen Interesse für technologische Innovationen bringt sie Enthusiasmus u... mehr anzeigen

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund