X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 54CA3D1DA2E for ; Thu, 26 Feb 2004 14:17:51 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 28859-10 for ; Thu, 26 Feb 2004 10:17:52 -0400 (AST) Received: from smurfer.pastoraat (minas-2.demon.nl [212.238.194.105]) by svr1.postgresql.org (Postfix) with ESMTP id DA32ED1BA21 for ; Thu, 26 Feb 2004 10:17:47 -0400 (AST) Received: from minas.demon.nl (athlon.pastoraat [192.168.1.1]) by smurfer.pastoraat (8.12.8/8.12.8) with ESMTP id i1QEL6hv026797 for ; Thu, 26 Feb 2004 15:21:07 +0100 Message-ID: <403E012D.9070607@minas.demon.nl> Date: Thu, 26 Feb 2004 15:22:37 +0100 From: Michiel Lange User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Help with triggers Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/355 X-Sequence-Number: 12529 Hello, I could use some help in getting to know how triggers are to be made exactly. Even with the documentation it is hard for me to understand all of it... maybe I think about it in a too complex manner, freezing my own brains... But here it is: I have a database that is about how ocomputers and phones are connected in a patch panel. For that I have three tables: patches(patch_id(serial, pkey), location(varchar, unique)); computers(computer_id(serial, pkey), name(varchar, unique), patch (unique,references patches.patch_id), ... and some more); phones(number(int4, pkey), owner(varchar), patch (unique,references patches.patch_id), ... and some more); (the database is not only about this information, there's quite some more, but this narrows the problem down) The point is: I can say that computers.patch is unique I can also say that phones.patch is unique but there's also this situation that you cannot connect a computer and a phone on the same patch_id, so if a patch is used for a computer it is not possible to use that patch also for the phones. (and vise versa) As far as I know there is no constraint that enforces this, so I will have to write a trigger... I can see a CREATE TRIGGER unique_patch_trg BEFORE UPDATE OR INSERT ON computers FOR EACH ROW but then... it would be easiest if something like IF EXIST patch IN phones.patch THEN ABORT ENDIF and about the same for the computers.patch... anyone who can help me learn how to get this done? Regards and thanks in advance, Michiel