Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hwnPe-0001Ca-7B for pgsql-general@arkaria.postgresql.org; Sun, 11 Aug 2019 12:57:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hwnOd-0001sG-FX for pgsql-general@arkaria.postgresql.org; Sun, 11 Aug 2019 12:56:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hwnOd-0001s8-5c for pgsql-general@lists.postgresql.org; Sun, 11 Aug 2019 12:56:27 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hwnOU-0005Mv-3G for pgsql-general@lists.postgresql.org; Sun, 11 Aug 2019 12:56:24 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 465zW204BMz1PQ7 for ; Sun, 11 Aug 2019 08:56:13 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 465zW160Lrz1ZVM; Sun, 11 Aug 2019 08:56:13 -0400 (EDT) Date: Sun, 11 Aug 2019 08:56:13 -0400 From: stan To: pgsql-general@lists.postgresql.org Subject: A question about trigger fucntion syntax Message-ID: <20190811125613.GA7408@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Good morning (at least is is morning East Coast USA time). I am trying to create a function to validate an attempted record insert, and I am having a hard time coming up with syntax that is acceptable. Here is the scenario I have a table that has (among other items) employee_key and work_type_key (both integer FOREIGN KEYS). Then I have another table that has the following structure: CREATE TABLE permitted_work ( employee_key integer , work_type_key integer , permit boolean DEFAULT FALSE NOT NULL , modtime timestamptz DEFAULT current_timestamp , FOREIGN KEY (employee_key) references employee(employee_key) , FOREIGN KEY (work_type_key) references work_type(work_type_key) , CONSTRAINT permit_constraint UNIQUE (employee_key , work_type_key) ); What I think I need to do is create a function that is fired on an insert, or update to the 1st table that verifies that there is an existing row in permitted_work that matches the combination of employee_key AND work_type_key AND has the value TRUE in the permit column. First does this seem to be a good way to achieve this constraint? If not, I am open to suggestions as to other ways to address this requirement. If it does, could someone give me a little help with th syntax of the needed function ?? Thanks for your time helping me with this. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin