【发布时间】:2022-11-28 20:05:06
【问题描述】:
我正在尝试将一天添加到 NOW() 并作为列的值返回。 这有效
SELECT NOW() as date
但这给出了一个错误
SELECT DATE_ADD( NOW(), INTERVAL 1 DAY) as date
有没有办法在 postgres 查询中实现这一点? 谢谢
【问题讨论】:
标签: sql postgresql
我正在尝试将一天添加到 NOW() 并作为列的值返回。 这有效
SELECT NOW() as date
但这给出了一个错误
SELECT DATE_ADD( NOW(), INTERVAL 1 DAY) as date
有没有办法在 postgres 查询中实现这一点? 谢谢
【问题讨论】:
标签: sql postgresql
如果您提到遇到的错误会更容易。我认为 PostgreSQL 中没有 date_add() 函数:
ERROR: function date_add(timestamp with time zone, interval) does not exist LINE 1: select date_add(now(), interval '1 day'); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.但是您可以使用常规的
+运算符将interval添加到timestamptz,由now()返回。 Demo:select now() + '1 day'::interval;
【讨论】: