DECLARE 处或附近的 PostgreSQL PgAgent 语法错误

问题描述 投票:0回答:2

有人能告诉我哪里出了问题吗? 我尝试使用 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 $$;
postgresql plpgsql pgadmin pgagent
2个回答
0
投票

PgAgent 似乎将您的代码转换为另一种格式,可能是字符串或其他格式,然后无法解析它。要理解这一点,请尝试:

  1. 从代码中删除一些特殊符号,如括号、引号等
  2. 尝试了解是pgAgent还是PostgreSQL报错 祝你好运!

0
投票

只有一个技巧。在按下保存按钮之前删除双美元符号。然后,步骤保存成功后,编辑它并带回双元并保存更改。

© www.soinside.com 2019 - 2024. All rights reserved.