Re: BUG #2138: Feature request: handle foreign key constraints on arrays

From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Bernhard Rosenkraenzer <bero(at)arklinux(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2138: Feature request: handle foreign key constraints on arrays
Date: 2006-01-03 20:27:52
Message-ID: c2d9e70e0601031227r4b9620cald0623c517c8cd159@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 1/2/06, Bernhard Rosenkraenzer <bero(at)arklinux(dot)org> wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2138
> Logged by: Bernhard Rosenkraenzer
> Email address: bero(at)arklinux(dot)org
> PostgreSQL version: 8.1.1
> Operating system: Linux (Ark Linux 2005.2)
> Description: Feature request: handle foreign key constraints on
> arrays
> Details:
>
> Best illustrated by an example:
>

an example of what *NOT* to do?

> A company has several offices and some employees who work in office #1 some
> of the time, and in office #2 at a different time.
>
> It would be nice to represent them in the database like this:
> CREATE TABLE offices(id SERIAL8 UNIQUE PRIMARY KEY, street VARCHAR(128));

UNIQUE and PRIMARY KEY are the same...

> CREATE TABLE employees(id SERIAL8 UNIQUE PRIMARY KEY, name VARCHAR(128),
> workplace BIGINT[] REFERENCES offices(id) ON UPDATE CASCADE);
>

what you should do is:

CREATE TABLE offices(id SERIAL8 PRIMARY KEY, street VARCHAR(128));

CREATE TABLE employees(id SERIAL8 UNIQUE PRIMARY KEY, name VARCHAR(128));

CREATE TABLE emp_offices (employee bigint not null references employees,
office bigint not null
references offices,
PRIMARY KEY(employee, office));

> Currently postgres refuses to do this because BIGINT[] and BIGINT are
> different types, it would be nice to simply apply the constraint to all
> entries in the array if a constraint for type X is applied to X[].
>

>

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-01-03 20:40:25 Re: [BUGS] BUG #2129: dblink problem
Previous Message Joe Conway 2006-01-03 19:30:33 Re: [BUGS] BUG #2129: dblink problem