【发布时间】:2021-10-07 13:38:36
【问题描述】:
当我执行这些脚本时,它在 postgresql 中运行;
select '2021-09-01'::Date - 1
select current_date -1
但是当我在函数中使用这种类型的减法时,postgresql 会给我这样的错误;
声明部分的函数用法:
v_date date := p_date - p_number;
ERROR: operator does not exist: date - numeric
【问题讨论】:
-
如果您以
p_number的身份通过3.14,您期望什么结果? -
该函数不会以十进制数作为输入,所以我对3.14没有任何期望。所以“v_date date := p_date - p_number::int;”为我工作。
-
更简洁的解决方案是将参数声明为
int
标签: postgresql date numeric subtraction