Re: Unique values on multiple tables

Поиск
Список
Период
Сортировка
От John Turner
Тема Re: Unique values on multiple tables
Дата
Msg-id CAMAP1QniggD9Vf3McUdXrGsj2z9botCFiwY2F3Fy04JcYX9fCQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Unique values on multiple tables  ("Sterpu Victor" <victor@caido.ro>)
Список pgsql-general
On Mon, Mar 28, 2016 at 2:32 AM, Sterpu Victor <victor@caido.ro> wrote:
 
table1
id
nr - integer
 
table2
id
id_table1 - FK in Table 1
valid_from - timestamp
 
There must be unique values for:
- nr - from table1
and
- YEAR(MIN(valid_from)) from table 2
Just trying to understand your goal here -

Is 'nr' supposed to be a count of records from table2 by 'id_table1' column?
And every single value for 'nr' within table1 must be unique - i.e., you need a table of unique counts?

I think I fixed the problem by executing the function AFTER insert or update but I'm not sure.
Until now the execution was before insert or update.

That doesn't sound right, I believe you would want to stick with execution of the DML to your presumable 'fact' table (table2) using a BEFORE trigger, *especially* if it's intended to enforce constraints.

It would be helpful if you could:
  • clarify/elaborate on how these 2 tables are supposed to relate to each other
  • post your actual trigger
  • provide us with some example inserts/updates
- John

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

Предыдущее
От: Roman Scherer
Дата:
Сообщение: How to quote the COALESCE function?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to quote the COALESCE function?