Create trigger for auto update function - Mailing list pgsql-sql

From Andrei Bintintan
Subject Create trigger for auto update function
Date
Msg-id 00e001c58b93$ad30b130$0b00a8c0@forge
Whole thread Raw
Responses Re: Create trigger for auto update function
Re: Create trigger for auto update function
Re: Create trigger for auto update function
List pgsql-sql
Hi to all,
 
I have a table:
create table hoy(
id serial,
pass varchar(40),
pass_md5 varchar(40);
 
Now, I want to write a trigger function that automatically updates the pass_md5 with the md5 function of the pass.
 
I tried this:
 
CREATE FUNCTION update_pass(integer) RETURNS integer AS $$
    UPDATE hoy SET pass_md5=md5(pass) WHERE id=$1;
   SELECT 1;
$$ LANGUAGE SQL;
 
and
 
CREATE TRIGGER triger_users_pass_md5
 AFTER INSERT OR UPDATE
 ON hoy
    EXECUTE PROCEDURE update_pass(integer);
 
 
But it works not.
When I create the trigger it says that function does not exist.
 
I also tried with:
 

CREATE OR REPLACE FUNCTION user2(integer)RETURNS TRIGGER AS'
BEGIN
    UPDATE users SET pass_md5=md5(pass) WHERE id=$1;
 return NULL;
END
'language plpgsql;
.... the same
 
 
Need some help!!!!
 
Andy.

pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Postgres for Fedora Core 2 OS ****************
Next
From: PFC
Date:
Subject: Re: Create trigger for auto update function