pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Trigger Documentation
2+ messages / 2 participants
[nested] [flat]

* Trigger Documentation
@ 2001-06-08 14:55  al_nunes@ciclotecnologia.com.br
  0 siblings, 1 reply; 2+ messages in thread

From: al_nunes@ciclotecnologia.com.br @ 2001-06-08 14:55 UTC (permalink / raw)
  To: pgsql-docs

Hi,

I could not find enough examples about the usage of triggers with
PostgreSQL. Searching in the list files, I found out that there are some
examples in contrib/spi/ directory, but this examples scared me a little
because all the triggers are written in C.

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;
' LANGUAGE 'plpgsql';


CREATE TRIGGER tr_ponto_ins BEFORE INSERT OR UPDATE ON ponto
    FOR EACH ROW EXECUTE PROCEDURE ins_ip();


Ie tryed to put something beetwen quotes, double-quotes, nothing
worked. Will I have to write an enormous trigger in C?

Regards,

Alvaro Nunes Melo





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Trigger Documentation
@ 2001-06-10 07:35  hubert depesz lubaczewski <depesz@depesz.pl>
  parent: al_nunes@ciclotecnologia.com.br
  0 siblings, 0 replies; 2+ messages in thread

From: hubert depesz lubaczewski @ 2001-06-10 07:35 UTC (permalink / raw)
  To: al_nunes@ciclotecnologia.com.br; +Cc: pgsql-docs

On Fri, 8 Jun 2001 11:55:08 -0300 (BRT)
al_nunes@ciclotecnologia.com.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 ...



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-06-10 07:35 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-08 14:55 Trigger Documentation al_nunes@ciclotecnologia.com.br
2001-06-10 07:35 ` hubert depesz lubaczewski <depesz@depesz.pl>

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