PL/PGSQL function with parameters - Mailing list pgsql-sql

From David Richter
Subject PL/PGSQL function with parameters
Date
Msg-id 3A76B039.9A59890@DKFZ-heidelberg.de
Whole thread Raw
Responses Re: PL/PGSQL function with parameters
List 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_tableALIAS 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
SETcolumn_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


pgsql-sql by date:

Previous
From: Manuel Cabido
Date:
Subject: Re: [HACKERS] How to modify type in table?
Next
From: Keith Perry
Date:
Subject: Problem with Day of Week