Re: foreign key question

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: foreign key question
Дата
Msg-id ig2ia7$qr1$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на foreign key question  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Список pgsql-sql
On 2011-01-05, Gary Stainburn <gary.stainburn@ringways.co.uk> wrote:
> On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote:
>> Now I want to set up a new access level table specific to the itinerary,
>> along the lines of
>>
>> u_id int4 not null references users(u_id)
>> fl_level int4 not null references facility_levels(16, fl_level)
>>
>> Firstly, is this possible, and secondly how would I do it?
>
> I've managed a work-around by creating a column that defaults to 16 and then 

> used ALTER TABLE ADD CONSTRAINT to add a foreign key with two pairs of keys.
>
> This feels wrong though as my table now has a column that is ultimately 
> redundant, and worse can be changed to a wrong value.
>
> Ok, I've sorted the last bit by adding a check constraint to make sure it 
> always contains 16, but it still feels wrong.

it feels wrong that's because it's not normalised,

the column with the 16's probably should not be there.

or possibly it should have rows with other values too.

look at how this table is useful and look for a more general way to
do it.


-- 
⚂⚃ 100% natural


В списке pgsql-sql по дате отправления:

Предыдущее
От: Gary Stainburn
Дата:
Сообщение: Re: foreign key question
Следующее
От: Iuri Sampaio
Дата:
Сообщение: explicit casts