当我调用max两个时间戳时,出现错误:
select max(now()::timestamp, to_timestamp('2021-01-01', 'YYYY-MM-DD')::timestamp);
-- ERROR: function max(timestamp without time zone, timestamp without time zone) does not exist
Run Code Online (Sandbox Code Playgroud)
我的实际用法是在 upsert 查询中,我想在其中写:
INSERT ...
ON CONFLICT (pk) DO UPDATE SET
ts = max(table.ts, excluded.ts)
Run Code Online (Sandbox Code Playgroud)
问题
有没有一种惯用的方法来获取 PostgreSQL 中两个时间戳之间的最大值?