If I do
INSERT INTO table1 (datetime1, datetime2) VALUES (NOW(),NOW())
Will the two fields always be identical in both columns?
Ditto for
INSERT INTO table1 (datetime1, datetime2) VALUES (NOW(),NOW())
,(NOW(),NOW())
Will all four database entries have the same value, or is it possible that row1 <> row2?
Note this is a theoretical question rather than a work-around
question.
I just really want to know the how and why.
The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).
CURRENT_TIMESTAMP and CURRENT_TIMESTAMP() are synonyms for NOW() . Returns the current time as a value in 'hh:mm:ss' or hhmmss format, depending on whether the function is used in string or numeric context. The value is expressed in the session time zone.
The CURRENT_TIMESTAMP function returns the current date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the GETDATE() function.
With Postgres now()
always returns the timestamp which denotes the beginning of the transaction.
So for your second example all four rows will have the same timestamp value.
If you want to have the "real" timestamp you have to use clock_timestamp()
.
More details are in the manual:
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With