title: crosstab postgres - line to column
body: <p>On my project, the data model changed and I have to do a new request to get information but in the past it looks like all data are in the same line, but now a part of that data are in an other table, and it returns me column. </p>
  
  <p>So my request returns:</p>
  
  <p><img src="https://i.stack.imgur.com/XoURM.jpg" alt="http://www.hostingpics.net/viewer.php?id=724031request.jpg"></p>
  
  <p>I thought it was easy but i don't really understand how the function <code>crosstab</code> works. I tried this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>    SELECT *
      FROM crosstab(
        'SELECT c.cd_type as typcou, c.dt_envoi as dtenvcou, c.commentaire as comment, c.signataire as signur
             FROM comm.courrier c
             WHERE c.id_formalite=1
       order by 1,2',
      'select lf.valeur as valeur from formalite.ligne_formalite lf, formalite.formalite f where lf.fk_formalite=f.id AND lf.fk_formalite=1'
       )
  
  AS c(typcou text, dtenvcou text, comment text, signataire text, valeur1 text, valeur2 text, valeur3 text);
  </code></pre>
  
  <p>However, I got</p>
  
  <blockquote>
    <p>ERREUR: invalid return type
    État SQL :42601
    Détail :Query-specified return tuple has 7 columns but crosstab returns 5.</p>
  </blockquote>
  
  <p>Can someone help me figure out what's wrong?</p>