Create trigger for auto update function
От | Andrei Bintintan |
---|---|
Тема | Create trigger for auto update function |
Дата | |
Msg-id | 00e001c58b93$ad30b130$0b00a8c0@forge обсуждение исходный текст |
Ответы |
Re: Create trigger for auto update function
Re: Create trigger for auto update function Re: Create trigger for auto update function |
Список | 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;
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);
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 по дате отправления: