PL/PGSQL function with parameters

From: David Richter <D(dot)Richter(at)DKFZ(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: PL/PGSQL function with parameters
Date: 2001-01-30 12:14:49
Message-ID: 3A76B039.9A59890@DKFZ-heidelberg.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Folks,

I wrote that function, wich doesn't work. I want to hand over the name
of the tables(relation_table, update_table) and a
column(column_to_fill). The intention is, to use the function also with
other tables(not hard coded).

BUT this error appears :
psql:restructure.sql:32: ERROR: parser: parse error at or near "$1"

I didn't found any solution.
I would be grateful , if I could get some more Examples(more than in the
Docu of www.postgresql.org and Bruce Monjiam's Book) about parameters in
PL/PGSQL - functions.
I would be no less grateful if anybody give detailed suggestions.

CREATE FUNCTION patient_study_restructure (text,text,text) RETURNS
integer AS '
DECLARE

relation_table ALIAS FOR $1;
update_table ALIAS FOR $2;
column_to_fill ALIAS FOR $3;
psr_rec record;
bound integer;
i integer := 0;

BEGIN
FOR psr_rec IN SELECT * FROM relation_table LOOP
UPDATE update_table
SET column_to_fill = psr_rec.parentoid
WHERE chilioid = psr_rec.childoid;
i := i + 1;
END LOOP;
IF NOT FOUND THEN RETURN 1;
ELSE RETURN i;
END IF;
END;

' LANGUAGE 'plpgsql';

SELECT
patient_study_restructure('relpatient_study000','study','patientoid');

Anybody (Jan Wieck?) who can make some sugestions on
the above will
receive my enthusiastic gratitude.

David

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliver Elphick 2001-01-30 12:22:05 Re: [HACKERS] How to modify type in table?
Previous Message clemens schmuck 2001-01-30 10:59:53 Hierarchical Queries