Re: The use of arrays as foreign key

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Mourad EL HADJ MIMOUNE <mimoune(at)ensma(dot)fr>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: The use of arrays as foreign key
Date: 2001-11-20 17:37:30
Message-ID: 20011120092856.M57432-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 20 Nov 2001, Mourad EL HADJ MIMOUNE wrote:

> Hi,
> I'am trying to use foreign key constraint on column of type int[] (
> array ) without success.
> Exemple:
>
> Create table course (id serial, name varchar);
> Create table student (id serial, name varchar, course int[3], Constraint
> f_key Foreign key (course) references course (id));
>
> plib_gene=# insert into course (name) values ('math');
> INSERT 600730 1
> plib_gene=# insert into course (name) values ('info');
> INSERT 600731 1
> plib_gene=# insert into course (name) values ('phys');
> INSERT 600732 1
> plib_gene=# insert into course (name) values ('chimie');
> INSERT 600733 1
> plib_gene=# insert into course (name) values ('sport');
> INSERT 600734 1
> plib_gene=# insert into student (name, course) values ('mourad', '{1,2,3}');
> ERROR: Unable to identify an operator '=' for types 'int4' and '_int4'
> You will have to retype this query using an explicit cast

Foreign keys need to be on comparable types (ie = is defined between them
for our implementation -- which is probably weaker than it'd need to be
for complete safety). Int array and int aren't comparable. In general
both sides of the foreign key should be the same base type.

> Why we can't use OID as a foreign key?
IIRC, there was a bug due to me not understanding how to get the system
attributes which I think Tom may have fixed for 7.2.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message wsheldah 2001-11-20 17:54:07 Re: A newbie's opinion - postgres NEEDS a Windows
Previous Message Randal L. Schwartz 2001-11-20 17:30:29 Re: Slightly OT: outer joins