Re: More on inheritance and foreign keys - Mailing list pgsql-hackers

From Andreas Pflug
Subject Re: More on inheritance and foreign keys
Date
Msg-id 44884886.5@pse-consulting.de
Whole thread Raw
In response to Re: More on inheritance and foreign keys  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: More on inheritance and foreign keys
List pgsql-hackers
Tom Lane wrote:
> "Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> writes:
> 
>>>The solution to the foreign key problem seems easy if I 
>>>modify PostgreSQL implementation and take off the ONLY word 
>>>from the SELECT query, but it's not an option for me, as I'm 
> 
> 
>>I think that the ONLY was wrong from day one :-(
> 
> 
> Well, sure, but until we have an implementation that actually *works*
> across multiple tables, it has to be there so that we can at least
> consistently support the current single-table semantics.  Until we
> have some form of cross-table unique constraint (index or whatever)

I managed uniqueness using normal indexes and ins/upd triggers on all 
child tables:

CREATE OR REPLACE FUNCTION checkchildsunique  RETURNS trigger AS
$BODY$BEGIN
IF EXISTS (SELECT 1 FROM foo Master         WHERE Master.primaryKeyCol = NEW.primaryKeyCol)
THEN   RAISE EXCEPTION 'Primary Key violation in table % on %',TG_RELNAME, TG_OP;
END IF;
RETURN NEW;
END;$BODY$ LANGUAGE 'plpgsql'

Shouldn't be too complicated to implement it as internal function.

Regards,
Andreas


pgsql-hackers by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Type of bare text strings
Next
From: "Jim C. Nasby"
Date:
Subject: Re: ADD/DROP INHERITS