Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f4MEc0A87897 for ; Tue, 22 May 2001 10:38:00 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4KJvdA50834 for ; Sun, 20 May 2001 15:57:39 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f4KJVqr53273 for pgsql-sql@postgresql.org; Sun, 20 May 2001 15:31:52 -0400 (EDT) (envelope-from news) From: =?iso-8859-1?Q?Hans=2DJ=FCrgen=20Sch=F6nig?= X-Newsgroups: comp.databases.postgresql.sql Subject: PL/pgSQL problem with variables Date: Sun, 20 May 2001 21:34:39 +0200 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 28 Message-ID: <3B081C4F.AC9E539C@cybertec.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: scrappy@hub.org X-Mailer: Mozilla 4.77 [de] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en To: pgsql-sql@postgresql.org X-Archive-Number: 200105/243 X-Sequence-Number: 3071 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