Re: Syntax question about returning value from an insert

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: stan <stanb(at)panix(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Syntax question about returning value from an insert
Date: 2019-12-26 05:16:50
Message-ID: 69bf1ac3-1b6c-f258-839e-bce9ee5d2abf@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/25/19 3:09 PM, stan wrote:
> On Wed, Dec 25, 2019 at 02:34:43PM -0800, Adrian Klaver wrote:
>> On 12/25/19 12:39 PM, stan wrote:
>>>

>>
>> Other approaches have been suggested, e.g. use a traditional FK
>> relationship. The big unknown in you present system is what:
>>
>> SELECT cost_category_key from t2 where type = 'Misc'
>>
>> will return. The implication is that it maybe more then one value(key) in
>> that case, which key would you use?
>
> There is more that that. There is a project number, so the actuall key
> represents the combination of project number, and cost category, Thire is a
> constraint on T2 that assures that these combinations will be unique.

So you have the unique key for the parent record of a FK relationship.

>
> When the 1st record for a project, that gets charged to the misc. cost
> category is entered, I need to assure that combination gets inserted into
> T2

When you start a new project seed it with the project number, cost
category, type='misc' record.

>
>> If not and cost_category_key: type is one to one then why have both?
>> Just make one unique(or PK) and the parent for the cost_category_key in t1.
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2019-12-26 05:17:22 Re: Syntax question about returning value from an insert
Previous Message Rob Sargent 2019-12-26 00:48:55 Re: Syntax question about returning value from an insert