在单个 PostgreSQL 查询中多次调用 now() 是否总是会给出相同的结果?

Will multiple calls to `now()` in a single PostgreSQL query always give the same result?

我想在 table 中插入一行;例如:

INSERT INTO some_table VALUES (now(), now());

我希望两列中的日期值相等。上面的查询对于这个要求安全吗?或者我应该使用其他替代方法,例如 sub-query/CTE:

INSERT INTO some_table (select t.now, t.now from (select now()) as t);

一般来说,这些函数是如何在 SQL 内部调用的? 调用函数的顺序(从左到right/right到左)是怎么决定的?给定的函数是否只被调用一次并为单个查询缓存 return 值?它是特定于供应商的吗?

documentationnow():

now() is a traditional PostgreSQL equivalent to transaction_timestamp()

关于transaction_timestamp()

These SQL-standard functions all return values based on the start time of the current transaction

因此在一个 SQL 语句中,now() 将始终 return 相同的值。