From: Hans-Jürgen Schönig <hs@cybertec.at>
To: pgsql-sql@postgresql.org
Subject: PL/pgSQL problem with variables
Date: Sun, 20 May 2001 21:34:39 +0200
Message-ID: <3B081C4F.AC9E539C@cybertec.at> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: hs@cybertec.at
Subject: Re: PL/pgSQL problem with variables
In-Reply-To: <3B081C4F.AC9E539C@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox