Re: Create trigger for auto update function

From: daq <daq(at)ugyvitelszolgaltato(dot)hu>
To: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
Cc: Pgsql-sql(at)postgresql(dot)org
Subject: Re: Create trigger for auto update function
Date: 2005-07-18 13:32:08
Message-ID: 1285936906.20050718153208@ugyvitelszolgaltato.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ying Lu 2005-07-18 15:40:05 About retrieving objects' priviledge info such as grantee & its privileges for a specific object (view, table, function, etc.)
Previous Message PFC 2005-07-18 13:21:51 Re: Create trigger for auto update function