From: | John Turner <fenwayriffs(at)gmail(dot)com> |
---|---|
To: | Sterpu Victor <victor(at)caido(dot)ro> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Unique values on multiple tables |
Date: | 2016-03-28 23:23:38 |
Message-ID: | CAMAP1QniggD9Vf3McUdXrGsj2z9botCFiwY2F3Fy04JcYX9fCQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Mar 28, 2016 at 2:32 AM, Sterpu Victor <victor(at)caido(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2016-03-28 23:30:56 | Re: How to quote the COALESCE function? |
Previous Message | Geoff Winkless | 2016-03-28 21:23:36 | Re: More correlated (?) index woes |