Received: from pugsly.m1group.com.au (unknown [203.38.113.174]) by postgresql.org (Postfix) with ESMTP id 4BE654759B5 for ; Tue, 23 Apr 2002 20:48:45 -0400 (EDT) Received: from scooby.m1group.com.au ([192.168.100.96]) by pugsly.m1group.com.au (8.11.2/8.11.0) with SMTP id g3O0fj004936 for ; Wed, 24 Apr 2002 08:41:45 +0800 From: Aaron Spiteri Date: Wed, 24 Apr 2002 00:42:53 GMT Message-ID: <20020424.425300@scooby.m1group.com.au> Subject: CREATING USERS To: pgsql-admin@postgresql.org X-Mailer: Mozilla/3.0 (compatible; StarOffice/5.2;Linux) X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Archive-Number: 200204/222 X-Sequence-Number: 4110 I am having some trouble with a PL/SQL script I have been trying to=20 write. The idea is that a table is created called user_table, This=20 stores extra information about each user on the system. There is a link=20 in the user_table called usename which links up to pg_shadow.username. I= =20 want to be able to create new users, alter existing users or drop users=20 depending on insertion, deletion or altercation of the user_table. The=20 code I wrote looks like this: CREATE FUNCTION insert_svoc_user() RETURNS OPAQUE AS ' DECLARE r record; b bool DEFAULT ''f''; BEGIN FOR r IN SELECT pg_shadow.usename FROM pg_shadow WHERE pg_shadow.usename= =20 =3D NEW.usename LOOP IF r.usename =3D NEW.usename THEN b :=3D ''t''; END IF; END LOOP; IF b =3D ''t'' THEN ALTER USER NEW.usename IN GROUP NEW.groname; ELSE CREATE USER NEW.usename IN GROUP NEW.groname;=20 END IF; RETURN NEW; END; ' LANGUAGE 'plpgsql'; /* * update_user * ----------- * This functions changes a users group on update of the user_table table */ CREATE FUNCTION update_svoc_user() RETURNS OPAQUE AS ' DECLARE r record; b bool DEFAULT ''f''; BEGIN FOR r IN SELECT usename FROM pg_shadow WHERE pg_shadow.usename =3D=20 NEW.usename LOOP IF r.username =3D NEW.usename THEN b :=3D ''t''; END IF; END LOOP; IF b =3D ''f'' THEN CREATE USER NEW.usename IN GROUP NEW.groname;=09=09 END IF IF NOT NEW.groname =3D OLD.groname AND b =3D ''t'' THEN ALTER USER NEW.usename IN GROUP NEW.groname; END IF; RETURN NEW; =09 END; ' LANGUAGE 'plpgsql'; /*=20 * delete_user * This function removes a user from the database if they are deleted=20 from * the user_det table. * */ CREATE FUNCTION delete_svoc_user() RETURNS OPAQUE AS ' DECLARE r record; BEGIN FOR r IN SELECT usename FROM pg_shadow WHERE pg_shadow.usename =3D=20 OLD.usename LOOP IF r.usename =3D OLD.usename THEN DROP USER OLD.usename; END IF; END LOOP; RETURN OLD; END; ' LANGUAGE 'plpgsql'; I am continuusly getting an error Can not copyObject() error writing to=20 $1. I have looked up the pg archives and think the problem may be a=20 limitation with in the PL SQL code, thus I was thinking of trying to=20 rewrite it in PL/ TCL can anyone give some pointers on how to do this. Aaron