title: Syntax error in plpgsql
body: <p>I have a stored procedure in PostgreSQL</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION show_senti_lang_setting(IN _senti_id bigint)
  RETURNS TABLE(lang_code character, native_name character varying, is_active boolean) AS
  $BODY$
  BEGIN
  RETURN QUERY 
      SELECT
          l.lang_code,
          l.native_name,
          (CASE WHEN s.senti_id is NULL THEN FALSE
              ELSE TRUE
          END) is_active
      FROM
          language l
      LEFT JOIN senti_lang s
      ON s.lang_code=l.lang_code
      AND s.senti_id=_senti_id;
  END;
  $BODY$
  LANGUAGE plpgsql VOLATILE STRICT;
  </code></pre>
  
  <p>The Error is:</p>
  
  <pre><code>ERROR:  syntax error at or near "$1"
  LINE 1: ...HEN s.senti_id is NULL THEN FALSE ELSE TRUE END)  $1  FROM l...
                                                           ^
  QUERY:   SELECT l.lang_code, l.native_name, (CASE WHEN s.senti_id is NULL THEN FALSE ELSE TRUE END)  $1  FROM language l LEFT JOIN senti_lang s ON s.lang_code=l.lang_code AND s.senti_id= $2 
  CONTEXT:  SQL statement in PL/PgSQL function "show_senti_lang_setting" near line 13
  
  ********** Error **********
  
  ERROR: syntax error at or near "$1"
  SQL state: 42601
  Context: SQL statement in PL/PgSQL function "show_senti_lang_setting" near line 13
  </code></pre>
  
  <p>Seems like the error is due to <code>CASE</code> in plpgsql. The same function in is working well in SQL:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION show_senti_lang_setting(bigint)
      RETURNS TABLE(lang_code character, native_name character varying, is_active boolean) AS
  $BODY$
  
      SELECT
          l.lang_code,
          l.native_name,
          CASE WHEN s.senti_id is NULL THEN FALSE
              ELSE TRUE
          END is_active
      FROM
          language l
      LEFT JOIN senti_lang s
      ON s.lang_code=l.lang_code
      AND s.senti_id=$1;
  
  $BODY$
    LANGUAGE sql VOLATILE STRICT;
  </code></pre>