X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 05364D9E75 for ; Wed, 21 Sep 2005 20:43:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37178-06 for ; Wed, 21 Sep 2005 23:43:19 +0000 (GMT) Received: from hotmail.com (bay109-f12.bay109.hotmail.com [64.4.19.22]) by svr1.postgresql.org (Postfix) with ESMTP id BA6C1D9F72 for ; Wed, 21 Sep 2005 20:43:20 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 21 Sep 2005 16:43:23 -0700 Message-ID: Received: from 64.4.19.200 by by109fd.bay109.hotmail.msn.com with HTTP; Wed, 21 Sep 2005 23:43:23 GMT X-Originating-IP: [64.4.19.200] X-Originating-Email: [seppwimmer@hotmail.com] X-Sender: seppwimmer@hotmail.com From: "Robert Wimmer" To: pgsql-interfaces@postgresql.org Subject: check foreign constraints before delete Date: Wed, 21 Sep 2005 23:43:23 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed X-OriginalArrivalTime: 21 Sep 2005 23:43:23.0690 (UTC) FILETIME=[4157A8A0:01C5BF06] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.789 required=5 tests=[DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, MSGID_FROM_MTA_HEADER=0, RCVD_IN_BL_SPAMCOP_NET=1.832, UPPERCASE_25_50=0.207] X-Spam-Level: *** X-Archive-Number: 200509/31 X-Sequence-Number: 5754 hi, i want to write a function in plpgsql, which checks a foreign key constraint violation on deleting a special value in my table. for example CREATE TABLE to (n NAME PRIMARY KEY); CREATE TABLE t1 (n_name NAME REFERENCES to(n), id INTEGER ...); CREATE FUNCTION check_before_delete(..some value ...) RETURNS INTEGER AS ' .. IF foreign_key_violation THEN RETURN -1 END IF; RETURN 0; .. END; ... so i can avoid the database errormessages. i checked some 'd' commands with the 'E' option. but i have no idea for a smart solution of this problem thanx in advance (tom?) sepp