foreign keys with constant part - Mailing list pgsql-general

From Marc Mamin
Subject foreign keys with constant part
Date
Msg-id C4DAC901169B624F933534A26ED7DF310861B619@JENMAIL01.ad.intershop.net
Whole thread Raw
List pgsql-general

Hello,

I have to define a foreign relation to something like a unique partial index.

I could do achieve this  with triggers, but I already have too much of them, which make the model hard to understand.

for now, I will just add a constant column which allows to define a standard foreign key.

Would an extension of the foreign keys declaration like following make sense, or does it too much break SQL standards ?

best regards,

Marc Mamin

create temp table t (

  a int,

  b int,

  constraint t_pk primary key (a, b)

);

create unique index t_partial on t (a) where b=5;

create temp table f (

 a int

)

alter table f add constraint f_fk  FOREIGN KEY ( a, 5 ) REFERENCES t (a,b);  --> t_pk

-- or

alter table f add constraint f_fk  FOREIGN KEY ( a ) REFERENCES t (a) WHERE  t.b=5; --> t_partial

for now:

create temp table f (

 a int,

five  int default 5   -- :-(

)

alter table f add constraint f_fk  FOREIGN KEY ( a, five ) REFERENCES t (a,b);

pgsql-general by date:

Previous
From: Toby Corkindale
Date:
Subject: Bug? Prepared queries continue to use search_path from their preparation time
Next
From: Jeremaine Johnson
Date:
Subject: Fulltext Search Function