title: unterminated dollar-quoted string at or near "$BODY$
body: <p>I do not know why I am getting the following error message:</p>
  
  <blockquote>
    <p>unterminated dollar-quoted string at or near "$BODY$</p>
  </blockquote>
  
  <p>Here is my SQL query:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION cdr_insert_function()
  RETURNS trigger AS
  $BODY$
  BEGIN
      if 
          (new.call_date &gt;= '2014-01-01' and new.call_date &lt;'2015-01-01') then
          insert into cdr_2014 values(new.*);
      elseif 
          (new.call_date &gt;= '2015-01-01' and new.call_date &lt;'2016-01-01') then
          insert into cdr_2015 values (new.*);
      elseif 
          (new.call_date &gt;= '2016-01-01' and new.call_date &lt; '2017-01-01') then
          insert into cdr_2016 values (new.*);
      elseif 
          (new.call_date &gt;='2017-01-01' and new.call_date &lt;'2018-01-01') then
          insert into cdr_2017 values (new.*);
      elseif 
          (new.call_date &gt;='2018-01-01' and new.call_date &lt;'2019-01-01') then
          insert into cdr_2018 values (new.*);
      elseif 
          (new.call_date &gt;='2019-01-01' and new.call_date &lt;'2020-01-01') then
          insert into cdr_2019 values (new.*);
      elseif 
          (new.call_date &gt;='2020-01-01' and new.call_date &lt;'2021-01-01') then
          insert into cdr_2020 values (new.*);
      elseif 
          (new.call_date &gt;='2021-01-01' and new.call_date &lt;'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;
  </code></pre>
  
  <p>It looks like it is terminated to me.</p>