gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnumed-devel] Can a single postgres table foreign key reference a colum


From: Jim Busser
Subject: [Gnumed-devel] Can a single postgres table foreign key reference a column in each of multiple different tables (in absence of inheritance)?
Date: Fri, 07 Oct 2011 08:21:59 -0700

I understand how

        dem.org_unit has columns

                pk
                fk_org (--> which references a primary key in dem.org)

however moving over to look at

        
http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v16/gnumed-schema.html#dem.table.lnk-org-unit2comm

table

        dem.lnk_org_unit2comm column

                fk_org_unit

is shown mapping to two foreign keys, as also seen if (in psql) doing

        \d+ dem.lnk_org_unit2comm

which returns, among other things, 

        Foreign-key constraints:
        "lnk_org_unit2comm_fk_org_unit_fkey" FOREIGN KEY (fk_org_unit) 
REFERENCES dem.org(pk) ON UPDATE CASCADE ON DELETE RESTRICT
        "lnk_org_unit2comm_fk_org_unit_fkey1" FOREIGN KEY (fk_org_unit) 
REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT 


So while the second constraint makes sense, that

                fk_org_unit ----- should reference ----->    dem.org_unit.pk

I am not sure how the same (single) fk_org_unit can reliably reference 
dem.org.pk (in absence of inheritance to keep the keys the same)?

… is fk_org_unit perhaps an array, consisting of this pair of primary keys:

        dem.org(pk), dem.org_unit(pk)

?

-- Jim




reply via email to

[Prev in Thread] Current Thread [Next in Thread]