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:
table1idnr - integertable2idid_table1 - FK in Table 1valid_from - timestampThere must be unique values for:- nr - from table1and- 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 по дате отправления: