| From: | stan <stanb(at)panix(dot)com> | 
|---|---|
| To: | pgsql-general(at)lists(dot)postgresql(dot)org | 
| Subject: | A question about trigger fucntion syntax | 
| Date: | 2019-08-11 12:56:13 | 
| Message-ID: | 20190811125613.GA7408@panix.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | stan | 2019-08-11 13:06:19 | Re: A question about trigger fucntion syntax | 
| Previous Message | Xinming Guo | 2019-08-11 11:35:50 | Invitation for OSS Community Research based in the University of Leeds! Many Thanks! |