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 723F852987 for ; Tue, 19 Jul 2005 04:53:51 -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 57213-04 for ; Tue, 19 Jul 2005 07:53:41 +0000 (GMT) Received: from ar-sd.net (unknown [82.77.155.72]) by svr1.postgresql.org (Postfix) with ESMTP id 0D16352952 for ; Tue, 19 Jul 2005 04:53:37 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 9FBD528BE7; Tue, 19 Jul 2005 10:45:11 +0300 (EEST) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14878-06; Tue, 19 Jul 2005 10:45:10 +0300 (EEST) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id B71AD28BDD; Tue, 19 Jul 2005 10:45:10 +0300 (EEST) Message-ID: <016401c58c37$43d52820$0b00a8c0@forge> From: "Andy" To: "daq16" Cc: References: <00e001c58b93$ad30b130$0b00a8c0@forge> <1285936906.20050718153208@ugyvitelszolgaltato.hu> Subject: Re: Create trigger for auto update function Date: Tue, 19 Jul 2005 10:55:41 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.569 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200507/157 X-Sequence-Number: 22135 > 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; I understand the ideea, but don't know how to apply it. I also receive the error that NEW must be definde as a rule. Still... not working... ----- Original Message ----- From: "daq" To: "Andrei Bintintan" Cc: Sent: Monday, July 18, 2005 4:32 PM Subject: Re: [SQL] Create trigger for auto update function > 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 > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > >