Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XWqu2-000430-Rg for pgsql-sql@arkaria.postgresql.org; Wed, 24 Sep 2014 18:02:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XWqu2-0004L3-AD for pgsql-sql@arkaria.postgresql.org; Wed, 24 Sep 2014 18:02:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XWqu0-0004IJ-W3 for pgsql-sql@postgresql.org; Wed, 24 Sep 2014 18:02:57 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XWqtt-00005W-22 for pgsql-sql@postgresql.org; Wed, 24 Sep 2014 18:02:55 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XWqtq-0006RD-Fn for pgsql-sql@postgresql.org; Wed, 24 Sep 2014 20:02:46 +0200 Received: from e177160207.adsl.alicedsl.de ([85.177.160.207]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Sep 2014 20:02:46 +0200 Received: from tim by e177160207.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Sep 2014 20:02:46 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-sql@postgresql.org To: pgsql-sql@postgresql.org From: Tim Landscheidt Subject: Re: FOREIGN KEY Reference on multiple columns Date: Wed, 24 Sep 2014 18:02:34 +0000 Organization: http://www.tim-landscheidt.de/ Lines: 31 Message-ID: <87y4t8rj5x.fsf@passepartout.tim-landscheidt.de> References: <4B4E89127868BD458A795430BCF4FD1328C51A6F@DVZSN-RA0325.bk.dvz-mv.net> <4B4E89127868BD458A795430BCF4FD1328C51ACB@DVZSN-RA0325.bk.dvz-mv.net> <4B4E89127868BD458A795430BCF4FD1328C51AF4@DVZSN-RA0325.bk.dvz-mv.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e177160207.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:GRvu2LAyB6X+2cH/HgYSeI32iYE= X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org "Weiss, Jörg" wrote: > I mean b must equal to c1 in the "other_table" where c2 has a certain value (for example c2 ). > For my first example: > CREATE TABLE parm > ( > complex varchar(20) NOT NULL, > para varchar(50) NOT NULL, > sort int4 NOT NULL DEFAULT 10, > value varchar(50) NULL, > CONSTRAINT parm_pkey PRIMARY KEY (complex, para, sort) > ) > Table user > CREATE TABLE user > ( > name varchar(20) NOT NULL, > type integer NULL > ) > In this case "type" of table user must equal to "value" of table "parm" and "para" must be "login_user" (for example) > [...] You can achieve that by duplicating the para column to the table user, adding a foreign key that matches both columns to table parm and checks in table user whether para is "login_user". That doesn't work for NULLable columns, though. Tim -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql