pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Markus Bertheau <twanger@bluetwanger.de>
To: olly@lfix.co.uk
Cc: pgsql-sql@postgresql.org
Subject: Re: multi column foreign key for implicitly unique columns
Date: Tue, 17 Aug 2004 19:45:15 -0700
Message-ID: <200408171945.15663.josh@agliodbs.com> (raw)
In-Reply-To: <1092736197.2627.12.camel@dicaprio.akademie1.de>
References: <1092734724.2627.4.camel@dicaprio.akademie1.de>
	<1092735576.28365.48.camel@linda>
	<1092736197.2627.12.camel@dicaprio.akademie1.de>

Markus,

Hey, I see you figured out a workaround to writing a trigger for this.  Let's 
see if we can make it work.

ERROR:  there is no unique constraint matching given keys
        for referenced table "objects"

The reason for this is that CASCADE behavior gets quite odd when there is an 
FK reference to a non-unique column.   We used to allow it, in 7.1, and I was 
responsible for a number of bug reports that led to us disallowing it.   It 
should be theoretically implementable and relationally sound but will require 
a *lot* of troubleshooting to make work.   So far, nobody's really interested 
enough.

However, you have an easy way out:

ALTER TABLE objects ADD CONSTRAINT obj_unq_2 UNIQUE (name, class_name);

This will add the unique constraint that Postgres wants without changing your 
data at all.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco



view thread (38+ messages)  latest in thread

Message-ID: <200408171945.15663.josh@agliodbs.com>
Permalink:  ../200408171945.15663.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200408171945.15663.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, twanger@bluetwanger.de, olly@lfix.co.uk
  Subject: Re: multi column foreign key for implicitly unique columns
  In-Reply-To: <200408171945.15663.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox