我使用的是 Postgres 9.0 版本。我想在日期中添加几个月以计算新日期并在表格中更新。这里要添加的月数将在整数变量中。我的代码如下:
declare numberofmonths smallint = 5;
update salereg1 set expdate = current_date + interval cast(numberofmonths as text) month;
上面的代码在转换时显示语法错误。我不知道如何将 numberofmonths
变量指定为文本。任何人都可以帮助我。我做错了什么..
最佳答案
尝试这样的事情:
update salereg1
set expdate = current_date + interval '1 month' * numberofmonths;
关于sql - 在 PostgreSQL 中向日期添加月份显示语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18851583/