title: Generate HTML from PostgreSQL function
body: <p>Can anyone help me with this? I have a task to write a function, which would generate HTML tables from given table name in PostgreSQL(plpgsql language).
  I have written this, but it's far from what I need. It would generate a table for columns I would give (at the moment just one), but I need to just give the table a name.</p>
  
  <blockquote>
    <p>CREATE OR REPLACE FUNCTION genhtml2(tablename text, columnname text)<br>
    RETURNS text AS 
    $BODY$ 
    DECLARE
        result text := '';
        searchsql text := '';
        var_match text := '';   BEGIN
        searchsql := 'SELECT ' || columnname || '
                    FROM ' || tablename || '';</p>
  
  <pre><code>result := '&lt;table&gt;';
  FOR var_match IN EXECUTE(searchsql) LOOP
      IF result &gt; '' THEN
          result := result || '&lt;tr&gt;' || var_match || '&lt;/tr&gt;';
      END IF;
  END LOOP;
  result :=  result || '&lt;/table&gt;';
  </code></pre>
    
    <p>RETURN result; END; $BODY$   LANGUAGE 'plpgsql' IMMUTABLE;</p>
  </blockquote>