Delete trigger

From: Leif Jensen <leif(at)crysberg(dot)dk>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Delete trigger
Date: 2015-09-18 08:22:56
Message-ID: 1709961348.5265057.1442564576985.JavaMail.zimbra@crysberg.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am running PostgreSQL 9.3.4. I have a simple table with 3 fields:

CREATE TABLE devicegroup (
groupid integer NOT NULL,
ctrlid integer NOT NULL,
userid integer NOT NULL
);
ALTER TABLE ONLY devicegroup
ADD CONSTRAINT pk_devicegroup PRIMARY KEY (groupid, ctrlid, userid);

I want to make sure that records are only deleted when all 3 fields are specified, so I tried make a trigger:

CREATE TRIGGER userDev_trig INSTEAD OF DELETE ON admdevgrid FOR EACH STATEMENT
EXECUTE PROCEDURE deleteUserDev();

which could check for NOT NULL on the 3 fields before actual doing the delete. Unfortunately this is not possible to do FOR EACH STATEMENT, and FOR EACH ROW would not give me the chance to check for NOT NULL.

Any ideas ?

Leif

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2015-09-18 08:44:59 Re: Delete trigger
Previous Message Guillaume Lelarge 2015-09-18 06:15:19 Re: Broken primary key after backup restore.