title: Concat text variables in postgresql function
body: <p>I have this code and I want to concatenate the variables but don't work.
  This is my DDL code for the view:</p>
  
  <pre><code>CREATE OR REPLACE function acd.add_credito2()
  RETURNS void
  SET SCHEMA 'acd'
  SET search_path = acd
  AS $$
  DECLARE
      auxsigla text;
      auxnome text;
      _sql text := 'CREATE OR REPLACE VIEW acd.teste AS SELECT md.matriz_disciplina_id AS id, dcp.nome, mc.curso, mc.versao AS matriz';    
      _join text := ' FROM matriz_disciplina as md LEFT JOIN disciplina as dcp ON md.disciplina_id = dcp.disciplina_id LEFT JOIN matriz_curricular as mc ON md.matriz_curricular_id = mc.matriz_curricular_id';
  
  BEGIN
      select into auxsigla, auxnome from ( select sigla, nome from acd.categoria_credito where categoria_credito_id = 9) as foo;
      _join := _join || ' LEFT JOIN (SELECT creditos, matriz_disciplina_id FROM acd.disciplina_credito WHERE categoria_credito_id = ' || x || ') AS ' || "auxsigla" ' ON ' || "auxsigla" || '.matriz_disciplina_id = md.matriz_disciplina_id';
          _sql := _sql || ', ' || "auxsigla" || '.' || auxnome || ' AS ' || auxnome;
  
      _sql := _sql || _join;
  
      EXECUTE _sql;
  END;
  $$ LANGUAGE plpgsql
  </code></pre>
  
  <p>So, when I execute the function</p>
  
  <pre><code>database-1=# select acd.add_credito2();
  </code></pre>
  
  <p>This error appears:</p>
  
  <pre><code>ERROR:  type "auxsigla" does not exist
  LINE 1: ...WHERE categoria_credito_id = ' || x || ') AS ' || "auxsigla"...
                                                               ^
  QUERY:  SELECT _join || ' LEFT JOIN (SELECT creditos, matriz_disciplina_id FROM acd.disciplina_credito WHERE categoria_credito_id = ' || x || ') AS ' || "auxsigla" ' ON ' || "auxsigla" || '.matriz_disciplina_id = md.matriz_disciplina_id'
  CONTEXT:  PL/pgSQL function add_credito2() line 13 at assignment
  </code></pre>
  
  <p>Can anyone help me? I don't know what to do now.</p>
  
  <p>(I know, this study view don't have a purpose but this is the idea that I want to use in the real view)</p>