title: How to avoid syntax error when returning text which includes a BEGIN statement in it?
body: <p>I'm trying to build a function that returns some text. The text includes a <code>BEGIN</code> statement which seems to cause an error:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION create_trigger() RETURNS TEXT AS $$
  BEGIN
      RETURN
      'CREATE OR REPLACE FUNCTION update_view() RETURNS trigger AS $$
         BEGIN -- error is near this begin
          IF TG_OP = ''INSERT''  THEN DO SOMETHING;
          ELSIF TG_OP = ''UPDATE'' THEN DO SOMETHING;
          END IF;
          RETURN NEW;
         END;
      $$ language plpgsql';
  END;
  $$ language plpgsql
  </code></pre>
  
  <p>I get a syntax error near the word <code>BEGIN</code> in the return statement and don't understand why, as I'm only trying to return some text. Is this because <code>plpgsql</code> recognizes the word <code>BEGIN</code> even if it is in a string portion of the code?</p>