From: | Daevor The Devoted <dollien(at)gmail(dot)com> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Enforce primary key on every table during dev? |
Date: | 2018-03-01 20:06:29 |
Message-ID: | CAAZnbVq+GVQ_3x8E0yLM5zztGnqpkd8=Vft7tZ43Dxrt+WZvWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Mar 1, 2018 at 8:52 PM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> On Thu, Mar 1, 2018 at 11:32 AM, Daevor The Devoted <dollien(at)gmail(dot)com>
> wrote:
>
>> Could you perhaps elaborate on how a surrogate key allows one to insert
>> garbage into the table? I'm afraid I don't quite get what you're saying.
>>
>
> A bit contrived but it makes the point:
>
> *Company:*
> C1 (id c1)
> C2 (id c2)
>
> *Department:*
> C1-D1 (id d1)
> C1-D2 (id d2)
> C2-D1 (id d3)
> C2-D2 (id d4)
>
> *Employee:*
> C1-E1 (id e1)
> C1-E2 (id e2)
> C2-E1 (id e3)
> C2-E2 (id e4)
>
> *Employee-Department:*
> e1-d1
> e2-d2
> e3-d2
> e4-d4
>
> The pair e3-d2 is invalid because e3 belongs to company c2 while d2
> belongs to company c1 - but we've hidden the knowledge of c# behind the
> surrogate key and now we can insert garbage into employee-department.
>
> David J.
>
>
This seems like hierarchical data, where employee's parent should be
department, and department's parent is company. So it wouldn't be possible
to "insert garbage" since Company is not stored in the Employee table, only
a reference to Department (and Company determined via Department). Isn't
that how normal hierarchical data works?
From | Date | Subject | |
---|---|---|---|
Next Message | marcelo | 2018-03-01 20:08:57 | Re: Enforce primary key on every table during dev? |
Previous Message | Ron Johnson | 2018-03-01 19:42:18 | Re: Enforce primary key on every table during dev? |