Skip site navigation (1) Skip section navigation (2)

Re: Trigger Documentation

From: hubert depesz lubaczewski <depesz(at)depesz(dot)pl>
To: al_nunes(at)ciclotecnologia(dot)com(dot)br
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: Trigger Documentation
Date: 2001-06-10 07:35:44
Message-ID: 20010610093544.14c48d82.depesz@depesz.pl (view raw or flat)
Thread:
Lists: pgsql-docs
On Fri, 8 Jun 2001 11:55:08 -0300 (BRT)
al_nunes(at)ciclotecnologia(dot)com(dot)br wrote:

> What I need to do now is very simple, I want to make a trigger that
check
> if some text field is null. If it is, I want to record something on
> it. What I was trying (unsuccessfully):
> CREATE FUNCTION ins_ip() RETURNS OPAQUE AS '
> BEGIN
>  IF NEW.<field> ISNULL THEN
>   NEW.<field> := "something";
>    RETURN NEW;
> END;

you're missing two things.
1st. there should be end if
2nd. is should be NEW.<field> := ''something'';

btw. it's better to do it with "DEFAULT" statement in create table.

depesz

-- 
hubert depesz lubaczewski                          http://www.depesz.pl/
------------------------------------------------------------------------
     najwspanialszą rzeczą jaką dało nam nowoczesne społeczeństwo,
      jest niesamowita wręcz łatwość unikania kontaktów z nim ...

In response to

pgsql-docs by date

Next:From: Anthony DyeDate: 2001-06-12 16:06:29
Subject: 404
Previous:From: Bruce MomjianDate: 2001-06-10 03:47:13
Subject: Re: Update needed for documentation

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group