can anyone help me with this. I have a task to rite 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 table for columns I would give(now just one), but I need to give just table 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 – intgr Nov 24 '10 at 13:32psql -H -c'select * from table'.
– nate c Nov 24 '10 at 19:13