有人能告诉我什么是错误的吗。我试图创建一个作业与使用PgAgent与声明一些变量。当我手动运行此代码,它工作成功。但当我试图将此代码放在作业步骤并保存它,它抛出了一个错误。
DO $$
DECLARE
start_date date;
dates date;
d SMALLINT;
counter integer := 0;
res date[];
treshold bigint;
BEGIN
TRUNCATE ditdemo.daily;
start_date:= now();
dates := start_date;
while counter <= 14 loop
dates := dates - INTERVAL '1 DAY';
select cal.is_holiday into d from ditdemo.calendar as cal where cal.calendardate = dates;
if d=0 then
res := array_append(res,dates);
counter := counter + 1;
end if;
/*
raise notice 'dates %', dates;
raise notice 'is holiday %', d;
raise notice 'result %', res;
* /
end loop;
insert into ditdemo.daily
select
time_bucket('1 day', j."timestamp") as day,
j.account,
count(*) as cnt
from ditdemo.jrnl as j
where
cast(j."timestamp" as date) in (select unnest(res)) AND
j.account not in (select account from ditdemo.user where is_service = 1)
group by day, j.account;
SELECT
round(PERCENTILE_CONT(0.95) WITHIN GROUP(ORDER BY d.cnt))
into treshold
FROM ditdemo.daily as d;
UPDATE ditdemo.calendar
SET daily_treshold = treshold
WHERE calendardate > start_date and calendardate <=(start_date::date + interval '7 day');
END $$;
1条答案
按热度按时间yvgpqqbh1#
看起来PgAgent将您的代码转换为另一种格式,可能是字符串或其他格式,然后无法解析它。要了解这一点,请尝试:
1.从代码中删除一些特殊的符号,如括号、引号等
1.试着了解它是错误的pgAgent或PostgreSQL好运气!