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.
CREATE OR REPLACE FUNCTION genhtml2(tablename text, columnname text)
RETURNS text AS $BODY$ DECLARE result text := ''; searchsql text := ''; var_match text := ''; BEGIN searchsql := 'SELECT ' || columnname || ' FROM ' || tablename || '';result := '<table>'; FOR var_match IN EXECUTE(searchsql) LOOP IF result > '' THEN result := result || '<tr>' || var_match || '</tr>'; END IF; END LOOP; result := result || '</table>';
RETURN result; END; $BODY$ LANGUAGE 'plpgsql' IMMUTABLE;
IMMUTABLE
qualifier with that function! PostgreSQL could make unsafe optimizations. Read: postgresql.org/docs/9.0/interactive/xfunc-volatility.html – intgrpsql -H -c'select * from table'.
– nate c