Re: [GENERAL] Unique values on multiple tables

2016-03-28 Thread John Turner
On Mon, Mar 28, 2016 at 2:32 AM, Sterpu Victor 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

Re: [GENERAL] Unique values on multiple tables

2016-03-28 Thread Jehan-Guillaume de Rorthais
Le Mon, 28 Mar 2016 12:44:51 +0200, Emre Hasegeli a écrit : > > Could I use lock tables to fix this? Is postgres automaticaly locking a > > table while running a trigger on that table? > > You can use LOCK TABLE. See the documentation: > > http://www.postgresql.org/docs/current/static/explicit-

Re: [GENERAL] Unique values on multiple tables

2016-03-28 Thread Emre Hasegeli
> Could I use lock tables to fix this? Is postgres automaticaly locking a > table while running a trigger on that table? You can use LOCK TABLE. See the documentation: http://www.postgresql.org/docs/current/static/explicit-locking.html -- Sent via pgsql-general mailing list (pgsql-general@post

Re: [GENERAL] Unique values on multiple tables

2016-03-28 Thread Sterpu Victor
-- Original Message -- From: "Emre Hasegeli" To: "Sterpu Victor" Cc: "PostgreSQL General" Sent: 28/3/2016 12:06:23 PM Subject: Re: [GENERAL] Unique values on multiple tables I have 2 tables and I must make asure unique values like this. table1

Re: [GENERAL] Unique values on multiple tables

2016-03-28 Thread Emre Hasegeli
> I have 2 tables and I must make asure unique values like this. > > 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 In situations like this, I add

Re: [GENERAL] Unique values on multiple tables

2016-03-27 Thread Sterpu Victor
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. -- Original Message -- From: "Sterpu Victor" To: "PostgreSQL General" Sent: 28/3/2016 9:32:17 AM Subject: [

[GENERAL] Unique values on multiple tables

2016-03-27 Thread Sterpu Victor
Hello I have 2 tables and I must make asure unique values like this. 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 I already made this with a function but in rare c