I have created my tables with a column (type: timestamp with timezone) and set its default value to now()
(current_timestamp()
).
I run a series of inserts in separate statements in a single function and I noticed all the timestamps are equal down to the (ms), is the function value somehow cached and shared for the entire function call or transaction?
now()
orcurrent_timestamp
areSTABLE
functions returning the timestamp when the transaction started.Consider one of the other options PostgreSQL offers, in particular
statement_timestamp()
.Per documentation:
That is expected and documented behaviour:
From the manual:
If you want something that changes each time you run a statement, you need to use
statement_timestamp()
or evenclock_timestamp()
(again see the description in the manual)