From: stan <stanb@panix.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Subject: Re: constrain with MATCH full and NULL values in referenced table
Date: Mon, 12 Aug 2019 13:44:24 -0400
Message-ID: <20190812174424.GA681@panix.com> (raw)
In-Reply-To: <402afcca-08f0-0b10-0ffb-b6d824c6b45e@aklaver.com>
References: <20190812170621.GA7359@panix.com>
<3d326318-0b75-f499-1865-5cbbcc15dae3@aklaver.com>
<20190812173006.GA7923@panix.com>
<402afcca-08f0-0b10-0ffb-b6d824c6b45e@aklaver.com>
On Mon, Aug 12, 2019 at 10:40:20AM -0700, Adrian Klaver wrote:
> On 8/12/19 10:30 AM, stan wrote:
> > > > The task_instance table is the one the original question was in reference
> > > > to.
> > > >
> > > > CREATE TABLE employee (
> > > > employee_key integer DEFAULT nextval('employee_key_serial')
> > > > PRIMARY KEY ,
> > > > id varchar(5) NOT NULL UNIQUE ,
> > > > first_name varchar NOT NULL,
> > > > );
> > > >
> > > > CREATE TABLE work_type (
> > > > work_type_key integer DEFAULT nextval('work_type_key_serial')
> > > > PRIMARY KEY ,
> > > > type smallint UNIQUE ,
> > > > descrip varchar UNIQUE ,
> > > > modtime timestamptz DEFAULT current_timestamp
> > > > );
> > > >
> > > > CREATE TABLE rate (
> > > > employee_key integer NOT NULL,
> > > > work_type_key integer NOT NULL,
> > > > rate numeric (5, 2) NOT NULL,
> > > > descrip varchar ,
> > > > 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 rate_constraint UNIQUE (employee_key , work_type_key)
> > > > );
> > > >
> > > >
> > > > CREATE TABLE task_instance (
> > > > task_instance integer DEFAULT nextval('task_instance_key_serial')
> > > > PRIMARY KEY ,
> > > > project_key integer NOT NULL ,
> > > > employee_key integer NOT NULL ,
> > > > work_type_key integer NOT NULL ,
> > > > hours numeric (5, 2) NOT NULL ,
> > > > work_start timestamptz ,
> > > > work_end timestamptz ,
> > > > modtime timestamptz DEFAULT current_timestamp ,
> > > > descrip varchar ,
> > >
> > > Aren't the marked ones below redundant?:
> > >
> > > > FOREIGN KEY (employee_key) references employee(employee_key) ,
> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > FOREIGN KEY (project_key) references project(project_key) ,
> > > > FOREIGN KEY (work_type_key) references work_type(work_type_key) ,
> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > FOREIGN KEY (work_type_key , employee_key) REFERENCES rate (work_type_key , employee_key) MATCH FULL
> > >
> > > They are covered above.
> > >
> > > > );
> >
> > OK, looks like learning time for me, again. Which is alwasy a good thing. My
> > thought here was that I needed to specify these on the dreivative table
> > (task_instnce). Are you teaching me that, since these constraints exist on
> > the tables that rate is derived from, I do not need to specify thmm for the
> > rate table?
>
> If I'm following what you are trying to do then:
>
> 1) task_instance is dependent on the information in rate being present for a
> given combination of (work_type_key , employee_key).
>
> 2) If 1) is correct then you cannot create a record in task_instance until a
> record exists in rate.
>
> 3) 2) means you have already established a relationship to employee and
> work_type via rate.
>
Ah subtle.
Makes sense.
In case it is not glaringly obvious to the casual observer, i am just
returning to the database world, after having spent many years in a totaly
unrelated on (power systens for large indutrials, if you are curios).
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
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, adrian.klaver@aklaver.com
Subject: Re: Subject: Re: constrain with MATCH full and NULL values in referenced table
In-Reply-To: <20190812174424.GA681@panix.com>
References: <20190812170621.GA7359@panix.com> <3d326318-0b75-f499-1865-5cbbcc15dae3@aklaver.com> <20190812173006.GA7923@panix.com> <402afcca-08f0-0b10-0ffb-b6d824c6b45e@aklaver.com> <20190812174424.GA681@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