pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Bintintan <klodoma@ar-sd.net>
To: pgsql-sql@postgresql.org
Subject: Create trigger for auto update function
Date: Mon, 18 Jul 2005 15:24:41 +0300
Message-ID: <00e001c58b93$ad30b130$0b00a8c0@forge> (raw)

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.

view thread (7+ messages)  latest in thread

Message-ID: <00e001c58b93$ad30b130$0b00a8c0@forge>
Permalink:  ../00e001c58b93$ad30b130$0b00a8c0@forge/
Also on:    postgresql.org/message-id/00e001c58b93$ad30b130$0b00a8c0@forge

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: klodoma@ar-sd.net
  Subject: Re: Create trigger for auto update function
  In-Reply-To: <00e001c58b93$ad30b130$0b00a8c0@forge>

* 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