I want to write a function that creates a new column for every value found in the table but something seems to go wrong with the variable: CREATE FUNCTION transp() RETURNS int4 AS ' DECLARE col RECORD; cname varchar; BEGIN CREATE TABLE tmp_trans (label) AS SELECT label FROM view_inc_age_1; FOR col IN SELECT DISTINCT age_code FROM view_inc_age_1 LOOP cname := col.age_code; ALTER TABLE tmp_trans ADD COLUMN cname int4; END LOOP; RETURN 0; END; ' LANGUAGE 'plpgsql'; persons=# SELECT transp(); ERROR: parser: parse error at or near "$1" The problem occurs in the line containing "ALTER TABLE". Does anybody know what is going wrong? Hans ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster