Re: need trigger help

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: abdulwahid(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org (PgSql General)
Subject: Re: need trigger help
Date: 2005-05-09 19:03:58
Message-ID: 200505091903.j49J3xDv031377@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> So how can I create a trigger to automatically update the hash fields
> on updates and inserts?

Something like the following works for me:

create or replace function public.my_trigger()
returns trigger as '

NEW.hashfield = hashfunction(NEW.data1,NEW.data2);

RETURN NEW;
END;
' language 'plpgsql';

--------
create trigger my_trig
before insert or update on my_tablename
for each row
execute procedure public.my_trigger();

The 'RETURN NEW' part is very important, without it your hash field won't
get updated at all.
--
Mike Nolan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Murtagh 2005-05-09 19:25:20 Trigger that spawns forked process
Previous Message David Fetter 2005-05-09 18:50:23 Re: PostGreSQL -> SQL server