pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: stan <stanb@panix.com>
To: pgsql-general@lists.postgresql.org
Subject: A question about trigger fucntion syntax
Date: Sun, 11 Aug 2019 08:56:13 -0400
Message-ID: <20190811125613.GA7408@panix.com> (raw)

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






view thread (5+ messages)  latest in thread

Message-ID: <20190811125613.GA7408@panix.com>
Permalink:  ../20190811125613.GA7408@panix.com/
Also on:    postgresql.org/message-id/20190811125613.GA7408@panix.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: stanb@panix.com
  Subject: Re: A question about trigger fucntion syntax
  In-Reply-To: <20190811125613.GA7408@panix.com>
  References: <20190811125613.GA7408@panix.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox