Create trigger for auto update function

From: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Create trigger for auto update function
Date: 2005-07-18 12:24:41
Message-ID: 00e001c58b93$ad30b130$0b00a8c0@forge
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message PFC 2005-07-18 13:21:51 Re: Create trigger for auto update function
Previous Message Richard Huxton 2005-07-18 06:12:52 Re: [SQL] Postgres for Fedora Core 2 OS ****************