Re: Create trigger for auto update function

Поиск
Список
Период
Сортировка
От Andy
Тема Re: Create trigger for auto update function
Дата
Msg-id 016401c58c37$43d52820$0b00a8c0@forge
обсуждение исходный текст
Ответ на Create trigger for auto update function  ("Andrei Bintintan" <klodoma@ar-sd.net>)
Ответы Re: Create trigger for auto update function  (daq <daq@ugyvitelszolgaltato.hu>)
Список pgsql-sql
> 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;

I understand the ideea, but don't know how to apply it.
I also receive the error that NEW must be definde as a rule.

Still... not working...




----- Original Message ----- 
From: "daq" <daq@ugyvitelszolgaltato.hu>
To: "Andrei Bintintan" <klodoma@ar-sd.net>
Cc: <Pgsql-sql@postgresql.org>
Sent: Monday, July 18, 2005 4:32 PM
Subject: Re: [SQL] Create trigger for auto update function


> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>
> 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Dawid Kuroczko
Дата:
Сообщение: Re: Dumping table definitions
Следующее
От: daq
Дата:
Сообщение: Re: Create trigger for auto update function