agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: pgsql-sql@postgresql.org
Subject: Re: FOREIGN KEY Reference on multiple columns
Date: Wed, 24 Sep 2014 18:02:34 +0000
Message-ID: <87y4t8rj5x.fsf@passepartout.tim-landscheidt.de> (raw)
References: <4B4E89127868BD458A795430BCF4FD1328C51A6F@DVZSN-RA0325.bk.dvz-mv.net>
	<CAHZ=uVAE3cobpckU+oyYWwF+ENr0UmYAhgu+kRrwmOc+t=g1nw@mail.gmail.com>
	<4B4E89127868BD458A795430BCF4FD1328C51ACB@DVZSN-RA0325.bk.dvz-mv.net>
	<CAHZ=uVDa4cyfoEk5D5jeOJqmYgmf6PNJs59OSFtmqP0WBfN0+g@mail.gmail.com>
	<4B4E89127868BD458A795430BCF4FD1328C51AF4@DVZSN-RA0325.bk.dvz-mv.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

"Weiss, Jörg" <J.Weiss@dvz-mv.de> 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



view thread (10+ messages)  latest in thread

Message-ID: <87y4t8rj5x.fsf@passepartout.tim-landscheidt.de>
Permalink:  ../87y4t8rj5x.fsf@passepartout.tim-landscheidt.de/
Also on:    postgresql.org/message-id/87y4t8rj5x.fsf@passepartout.tim-landscheidt.de

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: tim@tim-landscheidt.de
  Subject: Re: FOREIGN KEY Reference on multiple columns
  In-Reply-To: <87y4t8rj5x.fsf@passepartout.tim-landscheidt.de>

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

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