【发布时间】:2015-08-25 20:15:32
【问题描述】:
我正在尝试创建一个简单的函数,但我似乎无法将参数传递给日期函数。
这是函数:
CREATE OR REPLACE FUNCTION test(source int,days text)
RETURNS integer AS $totals$
declare
totals integer;
BEGIN
select
count(id) into totals
from ad
where
createdate::date = date(current_date - interval '$2' day) and
source = $1;
RETURN totals;
END;
$totals$ LANGUAGE plpgsql;
【问题讨论】:
-
您的 Postgres 版本、表定义和您收到的错误消息将是 essential 详细信息。
-
是的,这里的答案有效。我正在测试该功能的旧版本...感谢您的深入回答。
标签: sql postgresql parameter-passing plpgsql date-arithmetic