Re: FOREIGN KEY Reference on multiple columns - Mailing list pgsql-sql

From Tim Landscheidt
Subject Re: FOREIGN KEY Reference on multiple columns
Date
Msg-id 87y4t8rj5x.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to FOREIGN KEY Reference on multiple columns  (Weiss, Jörg <J.Weiss@dvz-mv.de>)
Responses Re: FOREIGN KEY Reference on multiple columns
List pgsql-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




pgsql-sql by date:

Previous
From: Weiss, Jörg
Date:
Subject: Re: FOREIGN KEY Reference on multiple columns
Next
From: Weiss, Jörg
Date:
Subject: Re: FOREIGN KEY Reference on multiple columns