From: daq <daq@ugyvitelszolgaltato.hu>
To: Andrei Bintintan <klodoma@ar-sd.net>
Cc: Pgsql-sql@postgresql.org
Subject: Re: Create trigger for auto update function
Date: Mon, 18 Jul 2005 15:32:08 +0200
Message-ID: <1285936906.20050718153208@ugyvitelszolgaltato.hu> (raw)
In-Reply-To: <00e001c58b93$ad30b130$0b00a8c0@forge>
References: <00e001c58b93$ad30b130$0b00a8c0@forge>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: daq@ugyvitelszolgaltato.hu, klodoma@ar-sd.net
Subject: Re: Create trigger for auto update function
In-Reply-To: <1285936906.20050718153208@ugyvitelszolgaltato.hu>
References: <00e001c58b93$ad30b130$0b00a8c0@forge> <1285936906.20050718153208@ugyvitelszolgaltato.hu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox