| From: | Stefan Balzter <Email(at)SteBaSoft(dot)de> |
|---|---|
| To: | aalam(at)tatashare(dot)com, pgsql-general(at)postgresql(dot)org |
| Subject: | Re: trigger |
| Date: | 2005-11-18 15:05:40 |
| Message-ID: | 437DEDC4.6010401@SteBaSoft.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2005-11-18 15:10:22 | Re: How to debug a locked backend ? |
| Previous Message | Csaba Nagy | 2005-11-18 14:55:01 | Re: How to debug a locked backend ? |