Re: trigger - Mailing list pgsql-general

From Stefan Balzter
Subject Re: trigger
Date
Msg-id 437DEDC4.6010401@SteBaSoft.de
Whole thread Raw
In response to trigger  ("Aftab Alam" <aalam@tatashare.com>)
List pgsql-general
Aftab Alam schrieb:
> I want to create a trigger in PostgresSQL
>
> In trigger, Before inserting the record, if data is already in the
> table, the trigger fire the mesaage that data is already there, and
> after that trigger ckeck for next insert statement.

You write a function that returns the type "trigger" and checks whether
the data is already there (i.e. by SELECTing INTO a variable the number
of records with your given values and checking if the variable is >0).
If it is, let it shout out your NOTICE and RETURN NULL; if it's not,
RETURN NEW;
Afterwards, you create the actual trigger BEFORE INSERT ON your table
FOR EACH ROW and let it execute your recently written function :-)

Good luck,

Stefan Balzter

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How to debug a locked backend ?
Next
From: Csaba Nagy
Date:
Subject: Re: How to debug a locked backend ?