DECLARE处或附近出现PostgreSQL PgAgent语法错误

cwxwcias  于 2022-11-04  发布在  PostgreSQL
关注(0)|答案(1)|浏览(290)

有人能告诉我什么是错误的吗。我试图创建一个作业与使用PgAgent与声明一些变量。当我手动运行此代码,它工作成功。但当我试图将此代码放在作业步骤并保存它,它抛出了一个错误。

  1. DO $$
  2. DECLARE
  3. start_date date;
  4. dates date;
  5. d SMALLINT;
  6. counter integer := 0;
  7. res date[];
  8. treshold bigint;
  9. BEGIN
  10. TRUNCATE ditdemo.daily;
  11. start_date:= now();
  12. dates := start_date;
  13. while counter <= 14 loop
  14. dates := dates - INTERVAL '1 DAY';
  15. select cal.is_holiday into d from ditdemo.calendar as cal where cal.calendardate = dates;
  16. if d=0 then
  17. res := array_append(res,dates);
  18. counter := counter + 1;
  19. end if;
  20. /*
  21. raise notice 'dates %', dates;
  22. raise notice 'is holiday %', d;
  23. raise notice 'result %', res;
  24. * /
  25. end loop;
  26. insert into ditdemo.daily
  27. select
  28. time_bucket('1 day', j."timestamp") as day,
  29. j.account,
  30. count(*) as cnt
  31. from ditdemo.jrnl as j
  32. where
  33. cast(j."timestamp" as date) in (select unnest(res)) AND
  34. j.account not in (select account from ditdemo.user where is_service = 1)
  35. group by day, j.account;
  36. SELECT
  37. round(PERCENTILE_CONT(0.95) WITHIN GROUP(ORDER BY d.cnt))
  38. into treshold
  39. FROM ditdemo.daily as d;
  40. UPDATE ditdemo.calendar
  41. SET daily_treshold = treshold
  42. WHERE calendardate > start_date and calendardate <=(start_date::date + interval '7 day');
  43. END $$;
yvgpqqbh

yvgpqqbh1#

看起来PgAgent将您的代码转换为另一种格式,可能是字符串或其他格式,然后无法解析它。要了解这一点,请尝试:
1.从代码中删除一些特殊的符号,如括号、引号等
1.试着了解它是错误的pgAgent或PostgreSQL好运气!

相关问题