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 7C1B852C92 for ; Mon, 18 Jul 2005 10:32:18 -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 00593-08 for ; Mon, 18 Jul 2005 13:32:12 +0000 (GMT) Received: from wukifi.ugyvitelszolgaltato.hu (adsl215141.vnet.hu [62.77.215.141]) by svr1.postgresql.org (Postfix) with SMTP id A19FB52AD5 for ; Mon, 18 Jul 2005 10:32:10 -0300 (ADT) Received: (qmail 28212 invoked from network); 18 Jul 2005 12:43:39 -0000 Received: from unknown (HELO x-eef90d131bdb4) (193.80.82.4) by 193.80.82.16 with SMTP; 18 Jul 2005 12:43:39 -0000 Date: Mon, 18 Jul 2005 15:32:08 +0200 From: daq X-Mailer: The Bat! (v1.53d) Business Reply-To: daq16 X-Priority: 3 (Normal) Message-ID: <1285936906.20050718153208@ugyvitelszolgaltato.hu> To: "Andrei Bintintan" Cc: Pgsql-sql@postgresql.org Subject: Re: Create trigger for auto update function In-Reply-To: <00e001c58b93$ad30b130$0b00a8c0@forge> References: <00e001c58b93$ad30b130$0b00a8c0@forge> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.073 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, RCVD_BY_IP, RCVD_IN_NJABL_DUL, RCVD_IN_SORBS_DUL, UPPERCASE_25_50 X-Spam-Level: ** X-Archive-Number: 200507/151 X-Sequence-Number: 22129 Hello Andrei, Monday, July 18, 2005, 2:24:41 PM, you wrote: AB> Hi to all, AB> I have a table: AB> create table hoy( AB> id serial, AB> pass varchar(40), AB> pass_md5 varchar(40); AB> Now, I want to write a trigger function that automatically updates the pass_md5 with the md5 function of the pass. AB> I tried this: AB> CREATE FUNCTION update_pass(integer) RETURNS integer AS $$ AB> UPDATE hoy SET pass_md5=md5(pass) WHERE id=$1; AB> SELECT 1; AB> $$ LANGUAGE SQL; AB> and AB> CREATE TRIGGER triger_users_pass_md5 AB> AFTER INSERT OR UPDATE AB> ON hoy AB> EXECUTE PROCEDURE update_pass(integer); What will be the param of the trigger procedure? Try this way: CREATE FUNCTION update_pass() RETURNS integer AS $$ UPDATE hoy SET pass_md5=md5(pass) WHERE id=new.id; SELECT 1; $$ LANGUAGE SQL; CREATE TRIGGER triger_users_pass_md5 AFTER INSERT OR UPDATE ON hoy FOR EACH ROW EXECUTE PROCEDURE update_pass; DAQ