未终止的美元引用字符串在或附近" $ BODY $

时间:2018-01-05 20:48:21

标签: postgresql

我不知道为什么会收到以下错误消息:

  

未终止的美元引用字符串在或附近" $ BODY $

这是我的SQL查询:

CREATE OR REPLACE FUNCTION cdr_insert_function()
RETURNS trigger AS
$BODY$
BEGIN
    if 
        (new.call_date >= '2014-01-01' and new.call_date <'2015-01-01') then
        insert into cdr_2014 values(new.*);
    elseif 
        (new.call_date >= '2015-01-01' and new.call_date <'2016-01-01') then
        insert into cdr_2015 values (new.*);
    elseif 
        (new.call_date >= '2016-01-01' and new.call_date < '2017-01-01') then
        insert into cdr_2016 values (new.*);
    elseif 
        (new.call_date >='2017-01-01' and new.call_date <'2018-01-01') then
        insert into cdr_2017 values (new.*);
    elseif 
        (new.call_date >='2018-01-01' and new.call_date <'2019-01-01') then
        insert into cdr_2018 values (new.*);
    elseif 
        (new.call_date >='2019-01-01' and new.call_date <'2020-01-01') then
        insert into cdr_2019 values (new.*);
    elseif 
        (new.call_date >='2020-01-01' and new.call_date <'2021-01-01') then
        insert into cdr_2020 values (new.*);
    elseif 
        (new.call_date >='2021-01-01' and new.call_date <'2022-01-01') then
        insert into cdr_2021 values (new.*);
    else
        raise exception 'Something is wrong, so an exception has been raised. Probably out of date range. Fix cdr_insert_function() !';
    end if;
    return null;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

看起来它终止于我。

0 个答案:

没有答案