title: How return dynamic number of columns in function?
body: <p>In <strong>PostgreSQL 11</strong> database I have table with 6 column. Next function return static number of defined columns.</p>
  
  <pre><code>CREATE FUNCTION CALCULATION(INTEGER)
  RETURNS TABLE(
      ORGANIZATION_ID INT4,
      ORGANIZATION_NAME VARCHAR,
      ORGANIZATION_RANG INT4,
      PARENT_ORGANIZATION_ID INT4,
      PARENT_ORGANIZATION_NAME VARCHAR,
      PARENT_ORGANIZATION_RANG INT4
  ) AS $$
      SELECT * FROM ANALYTICS;
  $$ LANGUAGE SQL;
  </code></pre>
  
  <p>How can I make an SQL function in Postgres 11 which return a result set with dynamic number of columns according to a parameter passed in?</p>
  
  <p>For example if I call <code>SELECT * FROM CALCULATION(2);</code>, function return first 2 columns.</p>
  
  <p>If this is not possible with an SQL function, is it possible with a PL/pgSQL function?</p>