X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5ED8A53FC0 for ; Fri, 15 Apr 2005 00:30:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38279-04 for ; Fri, 15 Apr 2005 03:30:05 +0000 (GMT) Received: from mail.savages.net (unknown [66.93.39.90]) by svr1.postgresql.org (Postfix) with ESMTP id D171453FBF for ; Fri, 15 Apr 2005 00:30:03 -0300 (ADT) Received: from [192.168.4.27] (s27 [::ffff:192.168.4.27]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by mail.savages.net with esmtp; Thu, 14 Apr 2005 20:30:02 -0700 id 00017B08.425F353A.0000443E Message-ID: <425F353A.6060700@mozapps.org> Date: Thu, 14 Apr 2005 20:30:02 -0700 From: shaun User-Agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: CREATE USER in side a TRIGGER FUNCTION Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.207 tagged_above=0 required=5 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200504/261 X-Sequence-Number: 21154 Hi I want to put login and user managment into the database for security reasons. I have a employee table. When I add a person to the employee table I want to create them in the database and when I remove a person I want to drop the person from the database also. How do you do it and what is wrong the the following code? shaun here is the add person trigger. CREATE FUNCTION insuser () RETURNS TRIGGER AS 'BEGIN IF NEW.role = ''clerk'' THEN EXECUTE CREATE USER NEW.login IN GROUP gp_clerk; ELSIF NEW.role = ''medic'' THEN EXECUTE CREATE USER NEW.login IN GROUP gp_medic; ELSIF NEW.role = ''super'' THEN CREATE USER NEW.login IN GROUP gp_super; ELSIF NEW.role = ''admin'' THEN CREATE USER NEW.login CREATEUSER IN GROUP gp_admin; ELSIF NEW.role = ''maint'' THEN CREATE USER NEW.login CREATEUSER IN GROUP gp_maint; END IF; RETURN NEW; END;' LANGUAGE plpgsql;