dbTalk Databases Forums  

[BUGS] BUG #2138: Feature request: handle foreign key constraints on arrays

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2138: Feature request: handle foreign key constraints on arrays in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bernhard Rosenkraenzer
 
Posts: n/a

Default [BUGS] BUG #2138: Feature request: handle foreign key constraints on arrays - 01-03-2006 , 12:33 PM







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:

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));
CREATE TABLE employees(id SERIAL8 UNIQUE PRIMARY KEY, name VARCHAR(128),
workplace BIGINT[] REFERENCES offices(id) ON UPDATE CASCADE);

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[].

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Reply With Quote
  #2  
Old   
Jaime Casanova
 
Posts: n/a

Default Re: [BUGS] BUG #2138: Feature request: handle foreign key constraints on arrays - 01-03-2006 , 02:28 PM






On 1/2/06, Bernhard Rosenkraenzer <bero (AT) arklinux (DOT) org> wrote:
Quote:
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?

Quote:
A company has several offices and some employees who work in office #1 so=
me
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...

Quote:
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));


Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.